Comments (1)
markdown-it AST of the provided example will become as below:
[
{
"type": "paragraph_open",
"tag": "p",
"attrs": null,
"map": [
0,
1
],
"nesting": 1,
"level": 0,
"children": null,
"content": "",
"markup": "",
"info": "",
"meta": null,
"block": true,
"hidden": false
},
{
"type": "inline",
"tag": "",
"attrs": null,
"map": [
0,
1
],
"nesting": 0,
"level": 1,
"children": [
{
"type": "html_inline",
"tag": "",
"attrs": null,
"map": null,
"nesting": 0,
"level": 0,
"children": null,
"content": "<span>",
"markup": "",
"info": "",
"meta": null,
"block": false,
"hidden": false
},
{
"type": "text",
"tag": "",
"attrs": null,
"map": null,
"nesting": 0,
"level": 0,
"children": null,
"content": "Inline: 🙂",
"markup": "🙂",
"info": "entity",
"meta": null,
"block": false,
"hidden": false
},
{
"type": "html_inline",
"tag": "",
"attrs": null,
"map": null,
"nesting": 0,
"level": 0,
"children": null,
"content": "</span>",
"markup": "",
"info": "",
"meta": null,
"block": false,
"hidden": false
}
],
"content": "<span>Inline: 🙂</span>",
"markup": "",
"info": "",
"meta": null,
"block": true,
"hidden": false
},
{
"type": "paragraph_close",
"tag": "p",
"attrs": null,
"map": null,
"nesting": -1,
"level": 0,
"children": null,
"content": "",
"markup": "",
"info": "",
"meta": null,
"block": true,
"hidden": false
},
{
"type": "html_block",
"tag": "",
"attrs": null,
"map": [
2,
3
],
"nesting": 0,
"level": 0,
"children": null,
"content": "<div>Block: 🙂</div>",
"markup": "",
"info": "",
"meta": null,
"block": true,
"hidden": false
}
]
Marp Core will transform an emoji within the content of inline
markdown-it token into marp_unicode_emoji
token, and render marp_unicode_emoji
token as a twemoji SVG image.
Lines 76 to 109 in 5c5eda0
On the other hand, the block element and its children are parsed as a single html_block
token. Marp Core does not transform emojis within html_block
token because may break raw HTML elements in some cases.
For emoji transformation in html_block
token correctly, should implement a robust HTML parser and entity resolver, that are working in both Node.js and the browser. Unfortunately, we have not yet implemented them due to a lot of concerns:
-
html_block
token may have only a part of the completed HTML block. So well-known HTML compliant parsers, such as browser's DOMParser, htmlparser2, and parse5 cannot use in our use case.<div class="😄"> # Markdown content 👍 </div>
In above case,
html_block
token will be split into<div class="😄">
and</div>
. When tried to parse and tranform these fragments with a known parser, the opening element will be unnecessarily closed due to HTML compliant behavior of auto-closing tags, and parsing the closing element will fail as invalid HTML. -
If applied a simple string replacement, the raw HTML block may break in some edge cases.
- Raw JS:
<script>document.title = "🙂";</script>
➡️<script>document.title = "<img class="emoji" draggable="false" alt="🙂" src="https://twemoji.maxcdn.com/2/svg/1f642.svg" data-marp-twemoji="">";</script>
- Raw JS:
from marp-core.
Related Issues (20)
- [v4?] New code highlighter
- [v4] Math syntax: GFM vs Pandoc based
- Slugify Markdown headers
- Relax HTML allowlist HOT 4
- CSS for highlight.js are not picked up since v3.1.1 HOT 5
- Content overlap with header and footer in included themes HOT 2
- Usage or marp-core in browser context HOT 2
- Emoji plugin: Allow using other emoji vendors HOT 3
- [bug] import failure `i is not a function` HOT 5
- Trouble rendering HTML and Markdown in the same line HOT 1
- A Marp constructor option, emoji.twemoji.base, seems not working HOT 1
- Overriding hljs-attr color does not work HOT 2
- [Regression] Auto-scaling for KaTeX block is always enable regardless of `@auto-scaling` theme metadata
- TypeError: u2 is not a function HOT 7
- Nanoid error HOT 4
- Images gallery HOT 1
- per-element animations HOT 2
- How to create, publish and use a theme? HOT 1
- Enable support for HTML code snippets by default HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marp-core.