mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-03 00:55:13 -07:00
fix(docs): restore playground output as Prism-highlighted HTML
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/src-min/mode-json.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/src-min/mode-json.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/src-min/mode-html.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/src-min/mode-html.js"></script>
|
||||||
<script>ace.config.set('basePath', 'https://cdn.jsdelivr.net/npm/[email protected]/src-min/');</script>
|
<script>ace.config.set('basePath', 'https://cdn.jsdelivr.net/npm/[email protected]/src-min/');</script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/prism.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/components/prism-markup.min.js"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{{ js('js/main') }}
|
{{ js('js/main') }}
|
||||||
|
|||||||
+3
-1
@@ -34,7 +34,9 @@
|
|||||||
<h2>Output</h2>
|
<h2>Output</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="pane-body">
|
<div class="pane-body">
|
||||||
<div class="editor output-editor" id="previewEl"></div>
|
<div class="output-preview" id="previewEl">
|
||||||
|
<pre class="highlight"><code class="language-markup" id="previewCode">{{__('playground.loading')}}</code></pre>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+40
-10
@@ -213,32 +213,26 @@
|
|||||||
background: var(--highlight-background)
|
background: var(--highlight-background)
|
||||||
|
|
||||||
.area-tpl .pane-body,
|
.area-tpl .pane-body,
|
||||||
.area-data .pane-body,
|
.area-data .pane-body
|
||||||
.area-output .pane-body
|
|
||||||
padding: var(--playground-inset)
|
padding: var(--playground-inset)
|
||||||
box-sizing: border-box
|
box-sizing: border-box
|
||||||
@media mq-mobile
|
@media mq-mobile
|
||||||
padding: 12px
|
padding: 12px
|
||||||
|
|
||||||
.area-tpl .ace_gutter,
|
.area-tpl .ace_gutter,
|
||||||
.area-data .ace_gutter,
|
.area-data .ace_gutter
|
||||||
.area-output .ace_gutter
|
|
||||||
display: none
|
display: none
|
||||||
width: 0
|
width: 0
|
||||||
min-width: 0
|
min-width: 0
|
||||||
|
|
||||||
.area-tpl .ace_editor,
|
.area-tpl .ace_editor,
|
||||||
.area-data .ace_editor,
|
.area-data .ace_editor,
|
||||||
.area-output .ace_editor,
|
|
||||||
.area-tpl .ace_scroller,
|
.area-tpl .ace_scroller,
|
||||||
.area-data .ace_scroller,
|
.area-data .ace_scroller,
|
||||||
.area-output .ace_scroller,
|
|
||||||
.area-tpl .ace_content,
|
.area-tpl .ace_content,
|
||||||
.area-data .ace_content,
|
.area-data .ace_content,
|
||||||
.area-output .ace_content,
|
|
||||||
.area-tpl .ace_text-layer,
|
.area-tpl .ace_text-layer,
|
||||||
.area-data .ace_text-layer,
|
.area-data .ace_text-layer
|
||||||
.area-output .ace_text-layer
|
|
||||||
background: transparent
|
background: transparent
|
||||||
|
|
||||||
.editor
|
.editor
|
||||||
@@ -249,9 +243,45 @@
|
|||||||
@media mq-mobile
|
@media mq-mobile
|
||||||
min-height: 180px
|
min-height: 180px
|
||||||
|
|
||||||
.output-editor
|
.output-preview
|
||||||
|
flex: 1 1 auto
|
||||||
|
min-height: 0
|
||||||
|
min-width: 0
|
||||||
|
width: 100%
|
||||||
|
overflow: auto
|
||||||
@media mq-mobile
|
@media mq-mobile
|
||||||
min-height: 120px
|
min-height: 120px
|
||||||
|
pre.highlight
|
||||||
|
margin: 0
|
||||||
|
min-height: 100%
|
||||||
|
width: 100%
|
||||||
|
box-sizing: border-box
|
||||||
|
padding: var(--playground-inset)
|
||||||
|
border: none
|
||||||
|
box-shadow: none
|
||||||
|
border-radius: 0
|
||||||
|
background: transparent
|
||||||
|
color: var(--highlight-foreground)
|
||||||
|
overflow-x: hidden
|
||||||
|
overflow-y: auto
|
||||||
|
white-space: pre-wrap
|
||||||
|
overflow-wrap: break-word
|
||||||
|
@media mq-mobile
|
||||||
|
padding: 12px
|
||||||
|
code
|
||||||
|
display: block
|
||||||
|
width: 100%
|
||||||
|
box-sizing: border-box
|
||||||
|
font-family: font-mono
|
||||||
|
font-size: 14px
|
||||||
|
line-height: 1.55
|
||||||
|
color: var(--highlight-foreground)
|
||||||
|
background: transparent
|
||||||
|
padding: 0
|
||||||
|
white-space: inherit
|
||||||
|
overflow-wrap: inherit
|
||||||
|
@media mq-mobile
|
||||||
|
font-size: 13px
|
||||||
|
|
||||||
.ace_editor
|
.ace_editor
|
||||||
font-family: font-mono
|
font-family: font-mono
|
||||||
|
|||||||
Vendored
+13
-11
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// playground
|
// playground
|
||||||
/* global liquidjs, ace */
|
/* global liquidjs, ace, Prism */
|
||||||
if (!/\/playground(?:\.html)?$/.test(location.pathname)) return;
|
if (!/\/playground(?:\.html)?$/.test(location.pathname)) return;
|
||||||
updateVersion(liquidjs.version);
|
updateVersion(liquidjs.version);
|
||||||
const engine = new liquidjs.Liquid({
|
const engine = new liquidjs.Liquid({
|
||||||
@@ -48,13 +48,14 @@
|
|||||||
const colorScheme = window.matchMedia('(prefers-color-scheme: dark)');
|
const colorScheme = window.matchMedia('(prefers-color-scheme: dark)');
|
||||||
const editor = createEditor('editorEl', 'liquid');
|
const editor = createEditor('editorEl', 'liquid');
|
||||||
const dataEditor = createEditor('dataEl', 'json');
|
const dataEditor = createEditor('dataEl', 'json');
|
||||||
const previewEditor = createEditor('previewEl', 'html', { readOnly: true });
|
const previewCode = document.getElementById('previewCode');
|
||||||
const indicatorTpl = document.querySelector('.area-tpl .pane-indicator');
|
const indicatorTpl = document.querySelector('.area-tpl .pane-indicator');
|
||||||
const indicatorData = document.querySelector('.area-data .pane-indicator');
|
const indicatorData = document.querySelector('.area-data .pane-indicator');
|
||||||
const indicatorOutput = document.querySelector('.area-output .pane-indicator');
|
const indicatorOutput = document.querySelector('.area-output .pane-indicator');
|
||||||
|
|
||||||
const editors = [editor, dataEditor, previewEditor];
|
const editors = [editor, dataEditor];
|
||||||
let previewValue = '';
|
let previewValue = '';
|
||||||
|
let hadPreview = false;
|
||||||
let renderTimer = null;
|
let renderTimer = null;
|
||||||
const RENDER_DELAY = 180;
|
const RENDER_DELAY = 180;
|
||||||
colorScheme.addEventListener('change', function() {
|
colorScheme.addEventListener('change', function() {
|
||||||
@@ -97,8 +98,7 @@
|
|||||||
editor.container.style.background = 'transparent';
|
editor.container.style.background = 'transparent';
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEditor(id, lang, options) {
|
function createEditor(id, lang) {
|
||||||
options = options || {};
|
|
||||||
const editor = ace.edit(id);
|
const editor = ace.edit(id);
|
||||||
applyEditorTheme(editor);
|
applyEditorTheme(editor);
|
||||||
editor.setOptions({
|
editor.setOptions({
|
||||||
@@ -117,10 +117,6 @@
|
|||||||
editor.renderer.$gutter.style.display = 'none';
|
editor.renderer.$gutter.style.display = 'none';
|
||||||
}
|
}
|
||||||
editor.renderer.setScrollMargin(0, 0, 0, 0);
|
editor.renderer.setScrollMargin(0, 0, 0, 0);
|
||||||
if (options.readOnly) {
|
|
||||||
editor.setReadOnly(true);
|
|
||||||
editor.getSession().setUseWrapMode(true);
|
|
||||||
}
|
|
||||||
bindClipboard(editor);
|
bindClipboard(editor);
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
@@ -179,8 +175,11 @@
|
|||||||
|
|
||||||
function setPreview(value) {
|
function setPreview(value) {
|
||||||
previewValue = value;
|
previewValue = value;
|
||||||
previewEditor.setValue(value, -1);
|
previewCode.textContent = value;
|
||||||
previewEditor.clearSelection();
|
if (window.Prism) {
|
||||||
|
delete previewCode.dataset.highlighted;
|
||||||
|
window.Prism.highlightElement(previewCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setIndicator(indicator, state) {
|
function setIndicator(indicator, state) {
|
||||||
@@ -221,7 +220,10 @@
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const html = await engine.parseAndRender(tpl, parsed);
|
const html = await engine.parseAndRender(tpl, parsed);
|
||||||
|
if (html !== '' || !hadPreview) {
|
||||||
setPreview(html);
|
setPreview(html);
|
||||||
|
if (html !== '') hadPreview = true;
|
||||||
|
}
|
||||||
setIndicator(indicatorTpl, 'idle');
|
setIndicator(indicatorTpl, 'idle');
|
||||||
setIndicator(indicatorData, 'idle');
|
setIndicator(indicatorData, 'idle');
|
||||||
setIndicator(indicatorOutput, 'ok');
|
setIndicator(indicatorOutput, 'ok');
|
||||||
|
|||||||
Reference in New Issue
Block a user