diff --git a/ChangeLog.md b/ChangeLog.md index fd134aa..bc17ee1 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,8 +2,18 @@ ## Unreleased changes -- Nothing +- Better CLI + +## 0.1.1 + +- **Added**: + - `Code Block` +- **Fixed**: + - fixed indentation problem of `Oreder List` and `Unordered List`. +- **Changed**: + - `Heading`: allow the punctuation of `·` + - `Comment`: allow to use `疏:` for comment. ## 0.1.0 -- Supported: `Heading`, `Ordered List`, `Unordered List`, `Image`, `Link`, `Comment`, `Quote`, `Inline` +- **Added**: `Heading`, `Ordered List`, `Unordered List`, `Image`, `Link`, `Comment`, `Quote`, `Inline` diff --git a/README.md b/README.md index abee9a5..f2524ca 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ Currently supported syntax: ### Headings -Headings are done through indentations, and there should **NOT** be punctuations in it. +Headings are done through indentations, and there should **NOT** be punctuations in it (with the exception of `·`). + Every **2** indentations adds one title level. ``` markdown @@ -38,9 +39,25 @@ Every **2** indentations adds one title level. A paragraph should only take up **ONE** line and each sentence should end with either `。?!:`. +
+ +Inline elements like `Image`, `URL` and `Inline` would not be parsed when they are in a *sentecne*. So you can only add they after a punctuation mentioned above or at the start of a line. + +
+ +Try to compare the following: + +For `有Haskell码曰:〔putStrLn "Hello"〕乃「安好」也。`, it will be parsed to `有Haskell码曰:`putStrLn "Hello"`乃「安好」也。` + +While `有Haskell码曰〔putStrLn "Hello"〕乃「安好」也。` will be parsed to `有Haskell码曰〔putStrLn "Hello"〕乃「安好」也。` + +Do notice there is a `:` in the first sentence separating them. + +
+ ### Blockquote -Starts with `「「` ends with `」」` +Blockquotes are wrapped in `「「` and `」」`. They should be in a separate line. Example: @@ -75,19 +92,21 @@ For unordered lists, use `〇`, and it ends with `【列終】`. ``` markdown 〇《滕王閣序》 +〇《醉翁亭記》 【列終】 - 《滕王閣序》 +- 《醉翁亭記》 ``` ### Comments -Comments start with `批:`: +Comments start with `批:` or `疏:`: ``` markdown 批:註釋也 - + ``` ### Images @@ -157,7 +176,7 @@ isShuzi x = x `elem` "零一二三四五六七八九十百千萬" | URL | ✓ | `【有扉者「[name]」通「[url]」也】` | | Comment | ✓ | Starts with `批:` | | Inline | ✓ | Wrapped in `〔` and `〕` | -| Code Block | ∞ | Wrapped in `〔〔書以:[language]` and `〕〕` | +| Code Block | 〇 | Wrapped in `〔〔書以:[language]` and `〕〕` | | Table | ? | - | | Bold | ? | - | | Italic | 𐄂 | There is no *italic* in Chinese | diff --git a/examples/example.jian b/examples/example.jian index e0c0570..266122d 100644 --- a/examples/example.jian +++ b/examples/example.jian @@ -22,6 +22,7 @@ 〇《醉翁亭記》 〇《岳陽樓記》 【列終】 +疏:此亦註釋也。 圖片篇 【有圖者「兩儀式」自「https://fgo.wiki/images/0/0b/215-卡面-1.png」來】 @@ -36,4 +37,4 @@ isShuzi :: Char -> Bool isShuzi x = x `elem` "零一二三四五六七八九十百千萬" 〕〕 -此多行代碼之示例也。 \ No newline at end of file +上者,多行代碼之示例也。 \ No newline at end of file diff --git a/examples/example.md b/examples/example.md index a27fdc1..d79e725 100644 --- a/examples/example.md +++ b/examples/example.md @@ -36,6 +36,7 @@ - 《醉翁亭記》 - 《岳陽樓記》 + ### 圖片篇 ![兩儀式](https://fgo.wiki/images/0/0b/215-卡面-1.png) @@ -59,5 +60,5 @@ isShuzi :: Char -> Bool isShuzi x = x `elem` "零一二三四五六七八九十百千萬" ``` -此多行代碼之示例也。 +上者,多行代碼之示例也。 diff --git "a/examples/\346\273\225\347\216\213\351\226\243\345\272\217.jian" "b/examples/\346\273\225\347\216\213\351\226\243\345\272\217.jian" index 0892207..a7836e8 100644 --- "a/examples/\346\273\225\347\216\213\351\226\243\345\272\217.jian" +++ "b/examples/\346\273\225\347\216\213\351\226\243\345\272\217.jian" @@ -1,4 +1,4 @@ -秋日登洪府滕王閣餞別序 +秋日登洪府滕王閣餞別序·王勃 豫章故郡,洪都新府。星分翼軫,地接衡廬。襟三江而帶五湖,控蠻荊而引甌越。物華天寶,龍光射牛斗之墟;人傑地靈,徐孺下陳蕃之榻。雄州霧列,俊彩星馳。臺隍枕夷夏之交,賓主盡東南之美。都督閻公之雅望,棨戟遙臨;宇文新州之懿範,襜帷暫駐。十旬休暇,勝友如雲。千里逢迎,高朋滿座。騰蛟起鳳,孟學士之詞宗;紫電青霜,王將軍之武庫。家君作宰,路出名區。童子何知?躬逢勝餞。 時維九月,序屬三秋。潦水盡而寒潭清,煙光凝而暮山紫。儼驂騑於上路,訪風景於崇阿。臨帝子之長洲,得仙人之舊館。層臺聳翠,上出重霄;飛閣流丹,下臨無地。鶴汀鳧渚,窮島嶼之縈廻;桂殿蘭宮,即岡巒之體勢。 披繡闥,俯雕甍。山原曠其盈視,川澤紆其駭矚。閭閻撲地,鐘鳴鼎食之家;舸艦彌津,青雀黃龍之舳。雲銷雨霽,彩徹區明。落霞與孤鶩齊飛,秋水共長天一色。漁舟唱晚,響窮彭蠡之濱;雁陣驚寒,聲斷衡陽之浦。 diff --git "a/examples/\346\273\225\347\216\213\351\226\243\345\272\217.md" "b/examples/\346\273\225\347\216\213\351\226\243\345\272\217.md" index 3a59c22..d2cf9c3 100644 --- "a/examples/\346\273\225\347\216\213\351\226\243\345\272\217.md" +++ "b/examples/\346\273\225\347\216\213\351\226\243\345\272\217.md" @@ -1,4 +1,4 @@ -# 秋日登洪府滕王閣餞別序 +# 秋日登洪府滕王閣餞別序·王勃 豫章故郡,洪都新府。星分翼軫,地接衡廬。襟三江而帶五湖,控蠻荊而引甌越。物華天寶,龍光射牛斗之墟;人傑地靈,徐孺下陳蕃之榻。雄州霧列,俊彩星馳。臺隍枕夷夏之交,賓主盡東南之美。都督閻公之雅望,棨戟遙臨;宇文新州之懿範,襜帷暫駐。十旬休暇,勝友如雲。千里逢迎,高朋滿座。騰蛟起鳳,孟學士之詞宗;紫電青霜,王將軍之武庫。家君作宰,路出名區。童子何知?躬逢勝餞。 diff --git a/src/JianParser.hs b/src/JianParser.hs index accea7c..d87d5c6 100644 --- a/src/JianParser.hs +++ b/src/JianParser.hs @@ -8,16 +8,16 @@ import Text.ParserCombinators.Parsec import Control.Monad ( void ) import Hanzi -data JianVal = Heading Int String +data JianVal = Heading Int String -- level context | Body [JianVal] | Line String | InLine String - | CodeBlock String String - | Image String String - | Link String String + | CodeBlock String String -- lang code + | Image String String -- name url + | Link String String -- name url | Comment String - | OrdList Int String - | UnoList String + | OrdList Int Int String -- indents order context + | UnoList Int String -- indents context | Quote Bool | End deriving (Show) @@ -27,8 +27,8 @@ regularParse p = parse p "(unknown)" heading :: Parser JianVal heading = do - lv <- optionMaybe $ many1 space - rest <- many1 letter + lv <- optionMaybe $ many1 space -- TODO: add restrictions to how many spaces can be used + rest <- many1 $ choice [letter, char '·'] choice [eof, void (char '\n')] return $ case lv of Just lv' -> Heading (length lv' `div` 2 + 1) rest @@ -56,7 +56,7 @@ inline = do codeBlock :: Parser JianVal codeBlock = do - string "〔〔書以:" + string "〔〔書以:" -- TODO: 「書以」 need to be changed to a more appropriate one lang <- many1 $ noneOf "\n" code <- many1 $ noneOf "〕" string "〕〕" @@ -85,23 +85,29 @@ url = do ordlist :: Parser JianVal ordlist = do + lv <- optionMaybe $ many1 space id <- many1 $ satisfy isShuzi char '、' txt <- many1 $ noneOf "\n" choice [eof, void (char '\n')] - return $ OrdList (shuziToInt id) txt + return $ case lv of + Just lv' -> OrdList (length lv') (shuziToInt id) (lv' ++ txt) + Nothing -> OrdList 0 (shuziToInt id) txt unordlist :: Parser JianVal unordlist = do + lv <- optionMaybe $ many1 space char '〇' txt <- many1 $ noneOf "\n" choice [eof, void (char '\n')] - return $ UnoList txt + return $ case lv of + Just lv' -> UnoList (length lv') txt + Nothing -> UnoList 0 txt comment :: Parser JianVal -comment = do +comment = do -- ! Only works in a separate line void $ many (char ' ') - string "批:" + choice [string "批:", string "疏:"] txt <- many1 $ noneOf "\n" return $ Comment txt @@ -155,13 +161,13 @@ renderBody x = case x of toMdLine :: JianVal -> String toMdLine x = case x of - Heading h t -> replicate h '#' ++ " " ++ t ++ "\n" - Body t -> concatMap renderBody t ++ "\n" - OrdList h t -> show h ++ ". " ++ t - UnoList t -> "- " ++ t - Comment t -> "" - Quote t -> if t then "
" else "
\n" - End -> "" + Heading h t -> replicate h '#' ++ " " ++ t ++ "\n" + Body t -> concatMap renderBody t ++ "\n" + OrdList i h t -> replicate i ' ' ++ show h ++ ". " ++ t + UnoList i t -> replicate i ' ' ++ "- " ++ t + Comment t -> "" + Quote t -> if t then "
" else "
\n" + End -> "" CodeBlock l c -> "``` " ++ l ++ c ++ "```\n" jianToMD :: String -> String