Skip to content

Commit

Permalink
Merge pull request #6 from Meowcolm024/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Meowcolm024 authored Feb 22, 2020
2 parents eff6072 + b2136fd commit ce43306
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 31 deletions.
14 changes: 12 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 `。?!:`.

<blockquote>

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.

<details>

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.

</details></blockquote>

### Blockquote

Starts with `「「` ends with `」」`
Blockquotes are wrapped in `「「` and `」」`. They should be in a separate line.

Example:

Expand Down Expand Up @@ -75,19 +92,21 @@ For unordered lists, use `〇`, and it ends with `【列終】`.

``` markdown
〇《滕王閣序》
〇《醉翁亭記》
【列終】
<!--Euqals to-->
- 《滕王閣序》
- 《醉翁亭記》
```

### Comments

Comments start with `批:`:
Comments start with `批:` or `疏:`:

``` markdown
批:註釋也
<!--Euqals to-->
<!--批:註釋也-->
<!--註釋也-->
```

### Images
Expand Down Expand Up @@ -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 |
3 changes: 2 additions & 1 deletion examples/example.jian
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
〇《醉翁亭記》
〇《岳陽樓記》
【列終】
疏:此亦註釋也。
圖片篇
【有圖者「兩儀式」自「https://fgo.wiki/images/0/0b/215-卡面-1.png」來】

Expand All @@ -36,4 +37,4 @@
isShuzi :: Char -> Bool
isShuzi x = x `elem` "零一二三四五六七八九十百千萬"
〕〕
此多行代碼之示例也
上者,多行代碼之示例也
3 changes: 2 additions & 1 deletion examples/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- 《醉翁亭記》
- 《岳陽樓記》

<!--此亦註釋也。-->
### 圖片篇

![兩儀式](https://fgo.wiki/images/0/0b/215-卡面-1.png)
Expand All @@ -59,5 +60,5 @@ isShuzi :: Char -> Bool
isShuzi x = x `elem` "零一二三四五六七八九十百千萬"
```

此多行代碼之示例也
上者,多行代碼之示例也

2 changes: 1 addition & 1 deletion examples/滕王閣序.jian
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
秋日登洪府滕王閣餞別序
秋日登洪府滕王閣餞別序·王勃
豫章故郡,洪都新府。星分翼軫,地接衡廬。襟三江而帶五湖,控蠻荊而引甌越。物華天寶,龍光射牛斗之墟;人傑地靈,徐孺下陳蕃之榻。雄州霧列,俊彩星馳。臺隍枕夷夏之交,賓主盡東南之美。都督閻公之雅望,棨戟遙臨;宇文新州之懿範,襜帷暫駐。十旬休暇,勝友如雲。千里逢迎,高朋滿座。騰蛟起鳳,孟學士之詞宗;紫電青霜,王將軍之武庫。家君作宰,路出名區。童子何知?躬逢勝餞。
時維九月,序屬三秋。潦水盡而寒潭清,煙光凝而暮山紫。儼驂騑於上路,訪風景於崇阿。臨帝子之長洲,得仙人之舊館。層臺聳翠,上出重霄;飛閣流丹,下臨無地。鶴汀鳧渚,窮島嶼之縈廻;桂殿蘭宮,即岡巒之體勢。
披繡闥,俯雕甍。山原曠其盈視,川澤紆其駭矚。閭閻撲地,鐘鳴鼎食之家;舸艦彌津,青雀黃龍之舳。雲銷雨霽,彩徹區明。落霞與孤鶩齊飛,秋水共長天一色。漁舟唱晚,響窮彭蠡之濱;雁陣驚寒,聲斷衡陽之浦。
Expand Down
2 changes: 1 addition & 1 deletion examples/滕王閣序.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 秋日登洪府滕王閣餞別序
# 秋日登洪府滕王閣餞別序·王勃

豫章故郡,洪都新府。星分翼軫,地接衡廬。襟三江而帶五湖,控蠻荊而引甌越。物華天寶,龍光射牛斗之墟;人傑地靈,徐孺下陳蕃之榻。雄州霧列,俊彩星馳。臺隍枕夷夏之交,賓主盡東南之美。都督閻公之雅望,棨戟遙臨;宇文新州之懿範,襜帷暫駐。十旬休暇,勝友如雲。千里逢迎,高朋滿座。騰蛟起鳳,孟學士之詞宗;紫電青霜,王將軍之武庫。家君作宰,路出名區。童子何知?躬逢勝餞。

Expand Down
46 changes: 26 additions & 20 deletions src/JianParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 "〕〕"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 -> "<!--" ++ t ++ "-->"
Quote t -> if t then "<blockquote>" else "</blockquote>\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 -> "<!--" ++ t ++ "-->"
Quote t -> if t then "<blockquote>" else "</blockquote>\n"
End -> ""
CodeBlock l c -> "``` " ++ l ++ c ++ "```\n"

jianToMD :: String -> String
Expand Down

0 comments on commit ce43306

Please sign in to comment.