LoginSignup
1
1

More than 5 years have passed since last update.

はてなダイアリー to Markdown > v0.1:sub list対応, v0.2-v0.3: スーパーpre記法対応

Last updated at Posted at 2018-04-23

はてなダイアリーは新規登録受付を停止している。
新規登録受付を停止したサービスが今後どの期間利用できるか不透明な中、はてなダイアリーの内容の別サービス移行をしている。

はてなダイアリーでは独自のはてな記法があるため、それをMarkdown形式に変換する必要がある。

はてな記法

code v0.1

リスト表記について対応した。

import sys

# on Python 3.5

'''
v0.1 Apr. 24, 2018
   - sub list is converted to Markdown style
'''

# read from stdin
lines = sys.stdin.readlines()

SPACE4 = "    "

for elem in lines:
    wrk = elem
    if "---" in wrk:
        wrk = wrk.replace("---", SPACE4 + SPACE4 + "-")
    if "--" in wrk:
        wrk = wrk.replace("--", SPACE4 + "-")
    print(wrk, end='')

使用方法

  • 変換したいはてなダイアリーの内容をstdinに貼る
  • 実行する
  • 出力されるstdoutをMarkdownとして利用する

再実行する場合はstdoutの「Clear the output」で出力をクリアしてから実行する。

code v0.2, v0.3

スーパーpre記法に対応した。

import sys

# on Python 3.5

'''
v0.3 Apr. 25, 2018
   - conv_super_pre_notation() takes cpp notation
v0.2 Apr. 25, 2018
   - add conv_super_pre_notation()
   - add conv_sublist()
v0.1 Apr. 24, 2018
   - sub list is converted to Markdown style
'''


def conv_sublist(astr):
    if "---" in astr:
        astr = astr.replace("---", SPACE4 + SPACE4 + "-")
    if "--" in astr:
        astr = astr.replace("--", SPACE4 + "-")
    return astr


def conv_super_pre_notation(astr):
    astr = astr.replace(">||", "```")
    astr = astr.replace(">|cpp|", "```cpp")
    astr = astr.replace(">|c|", "```c")
    astr = astr.replace("||<", "```")
    return astr

# read from stdin
lines = sys.stdin.readlines()

SPACE4 = "    "

for elem in lines:
    wrk = conv_sublist(elem)
    wrk = conv_super_pre_notation(wrk)
    print(wrk, end='')

TODO

自分の移行作業において必要な実装を逐次行う。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1