Skip to content

Commit

Permalink
Implement block quotes and lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkkrp committed Dec 6, 2017
1 parent e7850ca commit 4058e66
Show file tree
Hide file tree
Showing 5 changed files with 701 additions and 188 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,10 @@
* Added `scannerM` in `Text.MMark.Extension` and `runScannerM` in
`Text.MMark`.

* Added support for block quotes.

* Added support for unordered and ordered lists.

## MMark 0.0.1.1

* Fixed a bug in skipping of headers (only one newline after the header line
Expand Down
16 changes: 11 additions & 5 deletions README.md
Expand Up @@ -174,15 +174,23 @@ do, the closing `*` won't be in right-flanking position anymore. God dammit.

Block-level parsing:

* Headings, thematic breaks, code blocks should be separated from paragraphs
by at least one empty line. This makes the parser a lot simpler and forces
markdown sources to be in a more readable form too.
* Code blocks and thematic breaks should be separated from paragraphs and
lists by at least one empty line.
* If a line starts with hash signs it is expected to be a valid *non-empty*
header (level 1–6 inclusive). If you want to start a paragraph with
hashes, just escape the first hash with backslash and that will be enough.
* Setext headings are not supported for the sake of simplicity.
* Fenced code blocks must be explicitly closed by a closing fence. They are
not closed by the end of document or by start of another block.
* Lists and block quotes are defined by column at which their content
starts. Content belonging to a particular list or block quote should start
at the same column (or greater column, up to the column where indented
code blocks start).
* Block quotes are started by a single `>` character, it's not necessary to
put a `>` character at beginning of every line belonging to a quote (in
fact, this would make every line a separate block quote).
* Paragraphs can be interrupted by unordered list and ordered lists with any
valid starting index.

Inline-level parsing:

Expand All @@ -202,8 +210,6 @@ Inline-level parsing:
Not-yet-implemented things:

* Separate declaration of image's source and title is not (yet?) supported.
* Blockquotes are not implemented yet.
* Lists (unordered and ordered) are not implemented yet.
* Reference links are not implemented yet.
* HTML blocks are not implemented yet.
* HTML inlines are not implemented yet.
Expand Down
20 changes: 11 additions & 9 deletions Text/MMark/Internal.hs
Expand Up @@ -164,8 +164,8 @@ data Block a
-- ^ Paragraph, leaf block
| Blockquote [Block a]
-- ^ Blockquote container block
| OrderedList (NonEmpty [Block a])
-- ^ Ordered list, container block
| OrderedList Word (NonEmpty [Block a])
-- ^ Ordered list ('Word' is the start index), container block
| UnorderedList (NonEmpty [Block a])
-- ^ Unordered list, container block
| Naked a
Expand Down Expand Up @@ -336,24 +336,26 @@ defaultBlockRender = \case
newline
Paragraph (_,html) ->
p_ html >> newline
Blockquote blocks ->
blockquote_ (mapM_ defaultBlockRender blocks)
OrderedList items -> do
ol_ $ do
Blockquote blocks -> do
blockquote_ (newline <* mapM_ defaultBlockRender blocks)
newline
OrderedList i items -> do
let startIndex = [start_ (T.pack $ show i) | i /= 1]
ol_ startIndex $ do
newline
forM_ items $ \x -> do
li_ (mapM_ defaultBlockRender x)
li_ (newline <* mapM_ defaultBlockRender x)
newline
newline
UnorderedList items -> do
ul_ $ do
newline
forM_ items $ \x -> do
li_ (mapM_ defaultBlockRender x)
li_ (newline <* mapM_ defaultBlockRender x)
newline
newline
Naked (_,html) ->
html
html >> newline
where
mkId (Ois x) = [id_ (headerId x)]

Expand Down

0 comments on commit 4058e66

Please sign in to comment.