Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Markdown を拡張する話
Search
Koutarou Chikuba
August 29, 2017
Technology
9
8.7k
Markdown を拡張する話
at Markdown Night 2017 Summer
Koutarou Chikuba
August 29, 2017
Tweet
Share
More Decks by Koutarou Chikuba
See All by Koutarou Chikuba
CI/CD 改善の勘所
mizchi
0
54
極限環境で最終ビルドを絞るためのフロントエンド設計
mizchi
15
5.2k
Server Side JavaScript のためのバンドル最適化
mizchi
5
6.9k
V8 as a container on CDN Edge worker
mizchi
6
2.1k
Edge Side Frontend という新領域
mizchi
35
14k
バンドル最適化マニアクス at tfconf
mizchi
7
4.3k
「たかがJavaScript」のその先 #TECHPLAY
mizchi
47
20k
Deno Node 両刀
mizchi
6
2.4k
「フロントエンド領域」を再定義する
mizchi
50
36k
Other Decks in Technology
See All in Technology
製造業の会計システムをDDDで開発した話
caddi_eng
3
980
頻繁リリース × 高品質 = 無理ゲー? いや、できます!/20250306 Shoki Hyo
shift_evolve
0
160
Amazon EKS Auto ModeでKubernetesの運用をシンプルにする
sshota0809
0
110
OCI見積もり入門セミナー
oracle4engineer
PRO
0
120
AWS CDK コントリビュート はじめの一歩
yendoooo
1
120
Vision Language Modelを活用した メルカリの類似画像レコメンドの性能改善
yadayuki
9
1.3k
大規模サービスにおける カスケード障害
takumiogawa
2
260
職種に名前が付く、ということ/The fact that a job title has a name
bitkey
1
250
どっちの API SHOW?SharePoint 開発における SharePoint REST API Microsoft Graph API の違い / Which API show? Differences between Microsoft Graph API and SharePoint REST API
karamem0
0
110
問題解決に役立つ数理工学
recruitengineers
PRO
7
2.2k
非エンジニアにも伝えるメールセキュリティ / Email security for non-engineers
ykanoh
13
4k
スケールアップ企業のQA組織のバリューを最大限に引き出すための取り組み
tarappo
4
960
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
183
22k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
470
The Pragmatic Product Professional
lauravandoore
33
6.5k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
KATA
mclloyd
29
14k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.3k
Fireside Chat
paigeccino
37
3.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
7
620
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.4k
Transcript
MarkdownΛ֦ு͢Δ mizchi @ Markdown Night 2017 Summer
ࣗݾհ • @mizchi • SPA৬ਓ/Node.jsΤϯδχΞ • 4݄͔ΒϑϦʔϥϯε
ࠓ݄ͷਐḿ
ࣗͱMarkdown • લʑ৬(Quipper)ͰMarkdownΛ༻͍ͨڭࡐΦʔαϦϯάπʔ ϧͷ։ൃ • લ৬(Qiita)Ͱ Kobito ༻ͷ Markdown ίϯύΠϥͷ։ൃ
ۀMarkdownΦʔαϦϯάྺɺܭ3͙Β͍
୭͚ͷൃද͔ • ԿΒ͔ͷࣄͰ markdown Λ֦ு͠ͳ͚ΕͳΒͳ͍ਓ • AST ͕͖ͳਓ • GFM/Commonmark
ͷ༷ΛकΔ࣏తਖ਼͠͞ͱ͔ɺ͜ͷൃද ͷதʹ͓͍ͯͲ͏Ͱ͍͍…
ࠓͷൃද༰ • ֦ுͷࢦ • remark ΤίγεςϜͷհ • ΑΓΑ͍ WYSIWYG ͷͨΊʹ
ࠓ͞ͳ͍͜ͱ • GFM/Commonmark ͳͲͷྺ࢙ɾৄࡉ • ଞͷൃදऀ͕ޠͬͯ͘ΕΔͰ͠ΐ͏ • ੲॻ͍ͨࢿྉ: QiitaͱMarkdownͱίϯςϯπΦʔαϦϯά http://qiita.com/mizchi/items/
17bc6c123207be7e6636
֦ுͷࢦΛߟ͑Δ
Markdownͷྑ͍ • ϓϨʔϯςΩετͰ ൺֱత ಡΈ͍͢ • ҟͳΔαʔϏεͰ૬ޓӡ༻ੑ͕͋Δ (GitHub, Qiita, ͯ
ͳϒϩά, etc…)
Markdownͷྑ͍ • ϓϨʔϯςΩετͰ ൺֱత ಡΈ͍͢ • ҟͳΔαʔϏεͰ૬ޓӡ༻ੑ͕͋Δ (GitHub, Qiita, ͯ
ͳϒϩά, etc…) <= ???
ݱ࣮ • ͋ΔίϯύΠϥͷग़ྗͷɺผͷίϯύΠϥͰͷ࠶ݱࠔ • https://babelmark.github.io/ • Markdown ͱ͍͏ʮجຊతͳ֓೦ʯΛڞ༗͢Δ͚ͩͷɺผͳԿ ͔ͩͱࢥ͏ͷ͕ແ
Τοδέʔεͷྫ - a - b - c -d - e
https://babelmark.github.io/?text=-+a++++-+b++-+c+ ++-d+-+e
Markdownπʔϧ։ൃऀͱͯ͠ࢥ͏͜ͱ • ग़ྗϒϨΛग़͞ͳ͍ͨΊʹΫϥαόͰ୯Ұ࣮͕ྑ͍ • ΫϥΠΞϯτͰDOMΛԚ͞ͳ͍Α͏ʹ֦ு͍ͨ͠ • ϦΞϧλΠϜฤूͷͨΊʹதؒঢ়ଶ͔ΒVDOMΛు͖͍ͨ => ΑͬͯɺJS࣮͕Ұ൪خ͍͠ ※
Node.js ΤϯδχΞͷҙݟ
ԾDOMϓϨϏϡʔͷར • ૉͳ࣮͢Δͱɺଧ伴͝ͱʹ el.innerHTML = markdown.compile(md) ͕Δ • ංେԽ͢ΔͱೖྗͰக໋తʹ͘ͳΔ •
AST·Ͱύʔεͯ͠ԾDOMΞϧΰϦζϜʹͿΜ͛Δ͜ͱͰ 16ms ҎԼΛୡͰ͖Δ
Markdown֦ுͷࢦ 1.֦ு͠ͳ͍ 2.֦ு͢ΔͳΒߦّΑ͘
1. ֦ு͠ͳ͍ • ҟͳΔαʔϏεؒͷ૬ޓӡ༻ੑΛഁյ͢ΔͱɺMarkdownͰ͋ ΔϝϦοτ͕ബΕΔ • ओཁͳϦςϥϧ(* _ - #
+ >) ɺύʔεΛࠔʹ͢ΔͷͰ ৮Δ͖Ͱͳ͍
2. ֦ு͢ΔͳΒߦّΑ͘ • GFM ͷ fenced codeblock ͷதΛͲ͏ग़ྗ͢Δ͔࣮࣭ ࣗ༝ •
ϦςϥϧΛ֦ு͢Δ߹ɺGFMͰະ༷ͷϦςϥϧΛ͏($ %) • جຊࣗ༝هड़ͱ͍͏ͷΛΕͳ͍Α͏ʹ
ྫ: fenced-codeblock ֦ு \`\`\`mermaid graph TD; A-->B; A-->C; B-->D; C-->D;
\`\`\` mermaid.js ͷਤΛຒΊࠐΜͩΓ…
ྫ: ࣜϦςϥϧ֦ு $ x^2 + y^2 = z^2 $ •
$ ~ $ Λ math ϊʔυͱͯ͠ύʔε • Khan/KaTeX ͰίϯύΠϧͯ͠ຒΊࠐΉ ͱ͔͍ͨ͠
࣮ࡍʹ͜ΕΒΛ࣮ͯ͠ΈΑ͏ʂ
ͱࢥ͕ͬͨ… • લ৬ɺલʑ৬ͷϦϙδτϦʹίʔυஔ͍͖ͯͨ • ֓೦͚ͩஔ͍͍ͯ͘ͷͰ֤ࣗదʹ࣮͍ͯͩ͘͠͞
JS ͷ Markdown ॲཧܥ • chjj/marked • egoist/marked3 • showdown
• markdown-js • wooorm/remark
JS ͷ Markdown ॲཧܥ • chjj/marked • egoist/marked3 • showdown
• markdown-js • wooorm/remark <- ͓͢͢Ί
remark • github.com/wooorm/remark • wooorm ࢯࣗવݴޠॲཧͷݚڀऀɻ ଞɺ retext ͳͲ •
๛ͳϓϥάΠϯ: https://github.com/wooorm/ remark/blob/master/doc/plugins.md • GFMΦϓγϣϯɺ CommonmarkΦϓγϣϯ͕͋Δ
remark: ຊମ • remark-parse: Markdown Parser • remark-stringify: MarkdownAST =>
HTML • remark-cli: CLIπʔϧ
remark: ϓϥάΠϯͷྫ • remark-react: MarkdownAST => React • remark-lint: Style
Linter • remark-emoji: emoji֦ு • remark-lowlight: ίʔυͷγϯλοΫεϋΠϥΠτ • remark-inline-math: ֦ࣜு • remark-toc: ToCੜ
remark: ΤίγεςϜ • unist: Universal AST • mdast: Markdown AST
• hast: HTML AST ͦΕͧΕͷஈ֊͝ͱʹద༻Մೳͳ plugin ܊
unist https://github.com/syntax-tree/unist • ൚༻తͳ AST ఆٛ • ࣮ମͳ͍͕ traverse ͷ࣮͕͋Δ
mdast https://github.com/syntax-tree/mdast • Markdown ͷ AST ఆٛ • unist αϒηοτ
• ࣮ https://github.com/wooorm/mdast-util-to- hast
hast https://github.com/syntax-tree/hast • HTML ͷ AST ఆٛ • ͜ͷͷརͱͯ͠ɺ hast
=> HTML hast => React ͷந͕Ͱ͖Δ • αχλΠβͳͲ͜ͷͰ࣮
remark: ࣮ࡍͷ֦ுͷྲྀΕ 1.remarkͷϓϥάΠϯͱ࣮ͯ͠ • ASTͷ෦ॻ͖͑ͳΒे 2.ຊମΛ fork ࣮ͯ͠ • remark-parse
ͷ tokenizer Λ࣮ • mdast-util-to-hast ͰରԠ͢Δϊʔυͷ HTML ग़ྗΛ هड़
৭ʑࢼͨ͠ྫ • https://github.com/mizchi/remark • https://github.com/mizchi/mdast-util-to-hast ※ϓϥάΠϯͷ࡞ྫ͕গͳ͍࣌ʹຊମΛforkͯ͠ ࣜɺ emojiɺ@<username> Λ֦ுͨ͠ϦϙδτϦ
remark: ·ͱΊ • ෳͷASTͷεςʔδʹհೖՄೳͳJSͷMarkdownίϯύΠϥ • ϓϥάΠϯ๛Ͱศར • ΈΜͳϓϥάΠϯΛ࡞Ζ͏!!!
ΑΓΑ͍ WYSIWYG ͷઃܭͷͨΊʹ
ͦͦ WYSIWYG ඞཁ͔ • ͿͬͪΌ͚ϓϩάϥϚಉ࢜ͳΒෆཁ • Markdown ͕ྲྀߦͬͨͷ ෳࡶոحͳ WYSIWYG
ͷಈ • BtoC ͩͱආ͚ΒΕͳ͍ͷͰߟ͓͑ͯ͘
Մٯʹม͢Ε…ʁ
draft-js Ͱ markdown Λ૬ޓม • draft-js: FacebookͷWYSIWYGج൫ • draft-js-import-markdown Ͱ
markdown Λೖྗ • draft-js-export-markdown Ͱ markdown Λग़ྗ
draft-js Ͱ markdown Λ૬ޓม • ෦දݱͷϚελʔσʔλΛmarkdownͰѻ͏ͱɺWYSIWYG <=> Markdown Λ૬ޓʹΓସ͑ΒΕͯخ͍͠ͷͰ •
git Ͱ diff ΛऔΕΔ / PR ʹࡌͤΒΕΔ • Ͳͬͪͷਓຬ
͜ͷํ๏ͷ • draft-js ͷ WYSIWYG ͷϓϨϏϡʔ࣮ͱ Markdownग़ྗ ͷʮݟͨʯΛ͋Θͤͳ͍ͱ͍͚ͳ͍ • A
=> B => A ͕Մٯ͔ผͷ • draft-js ͷ࣮ͱ֦ு͕݁ߏਏ͍ (immutable.js ͷਂ͍ ཧղ͕ඞཁ) ͍ͣΕʮؾ߹ʯͰղܾ͢Δ͕…
ଞͷҊ • slate.js: draft-js ͷ alternative • prosemirror: ·͞ʹ markdown
<=> wysiwyg ͕֦ͩு ੑ͕͍ • markdown ͦͷͷʹϋΠϥΠτΛ͢Δ + ೖྗࢧԉ
݁ ؤுΕͰ͖Δ͕ؤுΓͨ͘ͳ͍
࠷ޙʹ • MarkdownߦّΑ֦͘ு͠·͠ΐ͏ • ༻్ʹԠͯ͡MarkdownίϯύΠϥΛ࡞Γ͍ͨํ @mizchi ͕͓ࣄঝΓ·͢
͓·͚1: ReactNativeͷՄೳੑ • mdast => react-native-elements ʹίϯύΠϧ͢Εɺ WebViewΛආ͚ͯߴͳϓϨϏϡʔ͕ՄೳͰ • ΕͰ͖Δ͜ͱΘ͔ͬͯΔ͚Ͳ…
• ࣌ؒͳͯͬͯ͘ͳ͍ • ͲͷυϝΠϯͷձࣾͰͦΕ͕ඞཁ͔ෆ໌
͓·͚2: Node.jsӡ༻ͷ • SEOॏࢹͷ߹ɺ JS࣮ͩͱ React ͷ Server Side Rendering
ͱಉ͡ɺͲ͜ͰNodeϓϩηεΛཧ͢Δ͔ͷ ͕ൃੜ • NodeϓϩηεΛͿΒԼ͛Δ͔ɺ AWS Lambda ্ͷϚΠΫϩα ʔϏεʹͯ͠͠·͏͔
͓·͚3: γϯλοΫεϋΠϥΠλʔ͕Ͱ͔͍ • highlight.js, lowlight ͍ͣΕɺΫϥΠΞϯτ͕ίʔυ ϋΠϥΠλʔΛ࣋ͭͱɺߏจఆٛͰαΠζ͕ΕΔ • ඞཁͳίʔυ͚ͩϩʔυ͢ΔΈΛ࡞ΕΔΑ͏ʹ͢Δͷ͕
͍͠
͓·͚4: WASM • C++/Rust ͰMarkdownίϯύΠϥॻ͍ͯ WASM ΛΫϥΠΞϯ τʹ࣋ͬͯ͘Εཧ্Ϣχόʔαϧ • ͦΕͦ͏͕ͩɺ·ͩք۾ͷ
WASM ͷݟ͕Γͳ͍ʂʂʂ
͓·͚5: Kobito for Windows ͷ࣮ • codemirror ͷ markdown ϋΠϥΠτϞʔυ
• codemirror ͷίʔυ͕ͬͯͯਏ͍ • γϯλοΫεϋΠϥΠλʔ͕Ͱ͔͍ΛҾ͖ͣͬͯͯ 1.5MB ͋Δ https://github.com/increments/kobito-oss/tree/ master/packages/markdown-editor
͓·͚6: md2react • ↑ kobito ͷҝʹ։ൃͨ͠ɻ • Reactͷ dangerouslySetInnerHTML ɺ໊લͷ௨ΓյΕ
Δ • ࠓ remark-react ͍ͬͯͩ͘͞
Ҏ্