Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
マークダウンパーサーの自作
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
suzakutakumi
December 11, 2021
Technology
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
マークダウンパーサーの自作
suzakutakumi
December 11, 2021
More Decks by suzakutakumi
See All by suzakutakumi
ピクロス作成の中間発表
suzakutakumi
0
110
しゅみろん
suzakutakumi
0
200
trap-search
suzakutakumi
1
66
Pyramid Makerの作成
suzakutakumi
0
60
絵文字ジェネレータボットの作成
suzakutakumi
0
170
send_discord
suzakutakumi
0
74
独自ドメインについて
suzakutakumi
0
67
ESP32とAlexaを用いたエアコン制御
suzakutakumi
0
1.4k
スターリンマージソート
suzakutakumi
3
650
Other Decks in Technology
See All in Technology
分析AIエージェントを育てる、動く環境を育てる
codatum
0
130
インバスケット試験対策アプリを 作って見えたAIエージェント構築 ナレッジ2選
shichijoyuhi
1
130
LLM機能を自作して分かるSnowflake Cortex AIの強み
nayuts
0
310
[2026 Oracle Technical Deep Dive] AI時代のデータベース基盤をどう選ぶ? Exadata Database Serviceの選択肢と使い分け (2026年9月17日開催)
oracle4engineer
PRO
0
230
継続的なAIコスト最適化
bgpat
1
180
[AWS 秋のクラウドオペレーション祭り 2026]AWS DevOps Agentで変わるリリースと運用対応 ~リリース管理機能と Directed actions のご紹介~
furuton
4
1k
雪かき部 #7 もう怖くない!SELECT文!
foursue
0
280
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
2
1.4k
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
17
120k
Claude Code本は、どのように執筆チームで書かれたか
oikon48
0
250
2026-10-01_MagicPod_QAハーネスエンジニアリングとQA組織の未来像
ynisqa1988
1
550
全社共通データ基盤をつくる。ソニーのDatabricks活用とデータガバナンス設計の裏側
sony
0
430
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
30 Presentation Tips
portentint
PRO
1
420
Code Reviewing Like a Champion
maltzj
528
40k
Being A Developer After 40
akosma
91
590k
GraphQLとの向き合い方2022年版
quramy
50
15k
Faster Mobile Websites
deanohume
310
32k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
The Cult of Friendly URLs
andyhume
79
7k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
350
Transcript
マークダウンパーサー の自作 2021/12/11 Zli 大LT
自己紹介 HN:朱雀 匠(本名:鈴木 拓眞) Twitter: @suzakutakumi3 Portfolio: http://suzakutakumi.mydns.jp/
None
None
マークダウンパーサーとは マークダウンをHTML等に変換してくれる奴です。
マークダウンを使うところ - Notion - Qiita - GitHub - esa.io -
VSCode
使ってて思ったこと - 色変えたい - 改行がスペース2個書かないとされないの意味わからん - 文字サイズも変更したい どうしたら良いのか?
自分で作る!
注意点! 構文解析とか文法解析とかは知らない 行きあたりばったりの何となくで作成しています
見出しの実装 if l>0 and row[0]=='#': cnt=1 while row[cnt]=='#': cnt+=1 if
row[cnt]==" ": row="<h%d>"%cnt+row[cnt+1:-4]+"</h%d>"%cnt これは1行:1行の対応なので、簡単に実装できました。
リンクの実装 ans=re.search(r"\[.+\]\(.+\)",row) if ans!=None: sl=ans.span() first=row[:sl[0]] second=row[sl[0]:sl[1]] last=row[sl[1]:] content=re.search(r"\[.+\]",second).span() link=re.search(r"\(.+\)",second).span()
row=first+'<a href="%s">%s</a>'%(second[link[0]+1:link[1]-1],second[content[0]+1:content[1]-1])+last こちらも1行:1行の対応なので、簡単に実装できました。 正規表現で、その行にリンクがあるか?リンクの位置などを抽出しています。
画像の実装 ans=re.search(r"!\[.*\]\(.+\)",row) if ans!=None: sl=ans.span() first=row[:sl[0]] second=row[sl[0]:sl[1]] last=row[sl[1]:] content=re.search(r"\[.+\]",second).span() link=re.search(r"\(.+\)",second).span()
row=first+'<img src="%s" alt="%s"/>'%(second[link[0]+1:link[1]-1],second[content[0]+1:content[1]-1])+last ほぼ、リンクと変わらないですね
リストの実装1 リストとは
リストの実装2 コードは省略 こちらは一番時間がかかっています。 リストのネストに対応しています。
サイズ変更の実装 ans=re.search(r"<[0-9]+>",row) if ans!=None: sl=ans.span() first=row[:sl[0]] second='<font size="%s">'%row[sl[0]+1:sl[1]-1] last=row[sl[1]:] row=first+second+last
fin_list.append("</font>") こちらも、正規表現を用いて、サイズの実装をしました。
色の実装 ans=re.search(r"<#[0-9a-fA-F]+>",row) if ans!=None: sl=ans.span() first=row[:sl[0]] second='<font color="%s">'%row[sl[0]+1:sl[1]-1] last=row[sl[1]:] row=first+second+last
fin_list.append("</font>") colorTexts=["black","gray","silver","white","blue","navy","teal","green","lime","aqua","yellow","red","fuchsia","olive"," purple","maroon"] for texts in colorTexts: ans=re.search("<%s>"%texts,row) if ans!=None: sl=ans.span() first=row[:sl[0]] second='<font color="%s">'%row[sl[0]+1:sl[1]-1] last=row[sl[1]:] row=first+second+last fin_list.append("</font>") こちらも正規表現を利用して、実装しています。
デモ
Webサーバでの実装 将来的には、自分のポートフォリオサイトで使いたいので、Webで編 集できるようにしたい!
Flaskで実装 from flask import Flask,render_template,request import sys sys.path.append( '../') from
command import MarkdownParser as MP app = Flask(__name__) @app.route('/') def Index(): return render_template( "index.html") @app.route('/test',methods=['GET','POST']) def Test(): data=request.get_data().decode() ans=MP.main(data.split( '\n')) return '\n'.join(ans) if __name__ == "__main__": app.run(debug=True) /testにアクセスすると、bodyの内容を 先ほど作ったマークダウンパーサーを呼び出し、変換しています。
デモ
今後について • シンタックスハイライトの対応やその他の便利機能を追加する • 構文解析などを習ったので、もう少ししっかりした設計にしたい • CSSをしっかりさせる • 自分のポートフォリオ用に適応させる
最後に 下のリンクからプログラムがおいてあるリポジトリを見ることができます。 https://github.com/suzakutakumi/MarkdownParser