Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions demo/demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,28 @@ table tr {
background-color: #ffffff;
border: 2px solid #cccccc;
}

#md-render-input {
width: 100%;
height: 300px;
}

#md-render-output {
padding: 1rem;
background-color: #ffffff;
border: 2px solid #cccccc;
}

.md-render-label {
margin: 0 0 0.5rem;
font-size: 0.8rem;
color: #5c5c5c;
text-transform: uppercase;
font-weight: 700;
}

.md-output-error {
color: red;
opacity: 0.6;
font-size: 0.8rem;
}
22 changes: 22 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,31 @@ const bootstrapCardEditor = () => {
activateButtons('#editor-card-wrapper', editor)
}

const bootstrapRenderer = () => {
const inputEl = document.querySelector('#md-render-input')
const outputEl = document.querySelector('#md-render-output')
const renderer = new window.MobiledocDOMRenderer()
inputEl.addEventListener('input', e => {
const text = e.target.value.trim()
if (!text) {
outputEl.innerHTML = ''
} else {
try {
const text = e.target.value.trim()
const json = JSON.parse(text)
outputEl.innerHTML = ''
outputEl.append(renderer.render(json).result)
} catch (e) {
outputEl.innerHTML = `<span class="md-output-error">${e.toString()}</span>`
}
}
})
}

document.addEventListener('DOMContentLoaded', () => {
bootstrapEditor()
bootstrapSimpleDemo()
bootstrapToolbarEditor()
bootstrapCardEditor()
bootstrapRenderer()
})
17 changes: 17 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</head>
<body>
<script src="./vendor/mobiledoc-pretty-json-renderer.js"></script>
<script src="./vendor/mobiledoc-dom-renderer.js"></script>
<script type="module" src="./demo.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js"></script>
<script>
Expand Down Expand Up @@ -392,5 +393,21 @@ <h2>Cards and Atoms</h2>
</div>
</div>
</section>

<section>
<h2>Render Mobiledoc</h2>
<p>Enter some mobiledoc json and see it rendered to html</p>

<div class="two-column">
<div class="column left tall">
<div class="md-render-label">Input:</div>
<textarea id="md-render-input" class="mobiledoc-output" placeholder="Enter mobiledoc..."></textarea>
</div>
<div class="column right tall">
<div class="md-render-label">Output:</div>
<div id="md-render-output"></div>
</div>
</div>
</section>
</body>
</html>
Loading
Loading