3bmd icon indicating copy to clipboard operation
3bmd copied to clipboard

Code-blocks, nested into a list items aren't supported

Open svetlyak40wt opened this issue 4 years ago • 1 comments

There are two problems:

  • Parsed code goes as a list item's sibling despite that it has the same indentation as item's content.
  • And they are parsed as inline code instead of CODE-BLOCK.
40ANTS-DOC-TEST/UTILS-TEST> (let ((3bmd-code-blocks:*code-blocks* t))
                              (3bmd-grammar:parse-doc "
* Added a warning mechanism, which will issue such warnings on words which looks
  like a symbol, but when real symbol or reference is absent:

  ```
  WARNING: Unable to find symbol \"API\" mentioned in (CL-INFO:@INDEX SECTION)
  ```
"))
((:BULLET-LIST
  (:LIST-ITEM
   (:PLAIN "Added" " " "a" " " "warning" " " "mechanism," " " "which" " "
    "will" " " "issue" " " "such" " " "warnings" " " "on" " " "words" " "
    "which" " " "looks" "
"
    "  " "like" " " "a" " " "symbol," " " "but" " " "when" " " "real" " "
    "symbol" " " "or" " " "reference" " " "is" " " "absent:")))
 (:PLAIN "  "
  (:CODE "
  WARNING: Unable to find symbol \"API\" mentioned in (CL-INFO:@INDEX SECTION)
")))
NIL
T

When there is now indentation, than code block is parsed correctly:

40ANTS-DOC-TEST/UTILS-TEST> (let ((3bmd-code-blocks:*code-blocks* t))
                              (3bmd-grammar:parse-doc "
```
WARNING: Unable to find symbol \"API\" mentioned in (CL-INFO:@INDEX SECTION)
```
"))
((3BMD-CODE-BLOCKS::CODE-BLOCK :LANG "" :PARAMS NIL :CONTENT
  "WARNING: Unable to find symbol \"API\" mentioned in (CL-INFO:@INDEX SECTION)"))
NIL
T

svetlyak40wt avatar Jul 29 '21 22:07 svetlyak40wt

Not sure about conformance, but indenting the list item's body by 4 spaces makes it parse correctly:

(let ((3bmd-code-blocks:*code-blocks* t))
                              (3bmd-grammar:parse-doc "
* Added a warning mechanism, which will issue such warnings on words which looks
  like a symbol, but when real symbol or reference is absent:

    ```
    WARNING: Unable to find symbol \"API\" mentioned in (CL-INFO:@INDEX SECTION)
    ```
"))
=> ((:BULLET-LIST
     (:LIST-ITEM
      (:PARAGRAPH "Added" " " "a" " " "warning" " " "mechanism," " "
       "which" " " "will" " " "issue" " " "such" " " "warnings" " "
       "on" " " "words" " " "which" " " "looks" "
"
       "  " "like" " " "a" " " "symbol," " " "but" " " "when" " "
       "real" " " "symbol" " " "or" " " "reference" " " "is" " "
       "absent:")
      (3BMD-CODE-BLOCKS::CODE-BLOCK :LANG "" :PARAMS NIL :CONTENT
       "WARNING: Unable to find symbol \"API\" mentioned in (CL-INFO:@INDEX SECTION)"))))
=> NIL
=> T

melisgl avatar Jan 24 '22 15:01 melisgl

3bmd is markdown, not commonmark, and in markdown

List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be indented by either 4 spaces or one tab.

I looked at trying to support it anyway, but I don't see any obvious way to support CommonMark properly with the existing parser. Lists in particular look annoying due to the arbitrary indentation.

For now, I'm closing this as a duplicate of #53, since it seems to work as expected with the original markdown style 4-space indent.

I might merge a PR if someone can figure out a clean way to make the current grammar support commonmark lists properly while maintaining compatibility with existing extensions, but the 'properly' part is important. I'd be less interested in changing from the current underspecified random markdown variant to another, slightly different, but still underspecified and random markdown variant.

3b avatar Jan 27 '23 09:01 3b