Skip to content

Commit

Permalink
support image embed.
Browse files Browse the repository at this point in the history
  • Loading branch information
stakiran committed May 1, 2021
1 parent 1322697 commit 69b5d9d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib_scblines2markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ def to_markdown_list_grammer(line, cur_indentdepth):
RE_LINK_ANOTHER_PAGE = re.compile(r'\[([^\-\*/])(.+?)\]([^\(]|$)')
RE_IMAGELINK_GYAZOURL_URL = re.compile(r'\[(https\:\/\/gyazo\.com\/)(.+?)( )http(s){0,1}\:\/\/(.+?)\]')
RE_IMAGELINK_URL_GYAZOURL = re.compile(r'\[http(s){0,1}\:\/\/(.+?)( )(https\:\/\/gyazo\.com\/)(.+?)\]')
RE_LINK_GYAZOURL = re.compile(r'\[(https\:\/\/gyazo\.com\/)(.+?)\]')
RE_LINK_URL_TEXT = re.compile(r'\[http(s){0,1}\:\/\/(.+?)( )(.+?)\]')
RE_LINK_TEXT_URL = re.compile(r'\[(.+?)( )http(s){0,1}\:\/\/(.+?)\]')
RE_LINK_MEDIAURL = re.compile(r'\[(http)(s){0,1}(\:\/\/)(.+?)\]')
Expand Down Expand Up @@ -1018,8 +1019,8 @@ def scb_to_markdown_in_line(line, cur_indentdepth, inblockstate_user, lines_cont
#
# link to another page の正規表現が扱える集合がえぐいので, 以下戦略を取る.
# - 1: まずは限定的なリンク表記から処理する
# メディアもリンクの一種として扱う(記法が本質的にリンクと同じ)
# 画像は gyazo url なら /raw つければアクセスできるので画像記法にしてしまう
# その他のメディアは, とりあえずリンクの一種として扱う(記法が本質的にリンクと同じ)
# - 2: 最後に link to another page を処理する
# このとき, 1: で処理した分は markdown link 書式になっているため
# ] の直後に ( が来ないパターンを弾くことで 1: を弾ける
Expand All @@ -1031,6 +1032,8 @@ def scb_to_markdown_in_line(line, cur_indentdepth, inblockstate_user, lines_cont
newline = re.sub(RE_IMAGELINK_GYAZOURL_URL, '<a href="http\\4://\\5" target="_blank" rel="noopener noreferrer">![](\\1\\2/raw)</a>', newline)
newline = re.sub(RE_IMAGELINK_URL_GYAZOURL, '<a href="http\\1://\\2" target="_blank" rel="noopener noreferrer">![](\\4\\5/raw)</a>', newline)

newline = re.sub(RE_LINK_GYAZOURL, '<a href="\\1\\2" target="_blank" rel="noopener noreferrer">![](\\1\\2/raw)</a>', newline)

newline = re.sub(RE_LINK_URL_TEXT, '[\\4](http\\1://\\2)', newline)
newline = re.sub(RE_LINK_TEXT_URL, '[\\1](http\\3://\\4)', newline)

Expand Down
6 changes: 3 additions & 3 deletions testdata/2_image_expect.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
画像 noindent

[media](https://gyazo.com/e4aae2345d1927c777db267138d1e419)
<a href="https://gyazo.com/e4aae2345d1927c777db267138d1e419" target="_blank" rel="noopener noreferrer">![](https://gyazo.com/e4aae2345d1927c777db267138d1e419/raw)</a>

<br>

画像 indent

- [media](https://gyazo.com/639242beda8d44936421325524cd99f3)
- [media](https://gyazo.com/777cfb7cd2528ebf90db1617ed659a40)
- <a href="https://gyazo.com/639242beda8d44936421325524cd99f3" target="_blank" rel="noopener noreferrer">![](https://gyazo.com/639242beda8d44936421325524cd99f3/raw)</a>
- <a href="https://gyazo.com/777cfb7cd2528ebf90db1617ed659a40" target="_blank" rel="noopener noreferrer">![](https://gyazo.com/777cfb7cd2528ebf90db1617ed659a40/raw)</a>

<br>

Expand Down

0 comments on commit 69b5d9d

Please sign in to comment.