Skip to content

Feat: fenced code blocks#13

Open
martin-martin wants to merge 3 commits intodlon:masterfrom
martin-martin:feat_fenced
Open

Feat: fenced code blocks#13
martin-martin wants to merge 3 commits intodlon:masterfrom
martin-martin:feat_fenced

Conversation

@martin-martin
Copy link
Copy Markdown

Changes the representation of <pre><code> to fenced code blocks instead of indented code blocks in Markdown.

Fenced code blocks allow for user-friendly addition of language syntax, e.g.:

```python
print("hello")
```

Syntax highlighting for these types of fenced code blocks is today widely available and make code snippets more legible.

I therefore suggest to replace this as the default rendering of <pre><code>.

@martin-martin
Copy link
Copy Markdown
Author

Fixes #11

Copy link
Copy Markdown
Owner

@dlon dlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm not necessarily opposed to the idea. Fenced code blocks are an extension of standard markdown, though, so it may have to be an option.

Comment thread html2markdown.py
elif tag.name == 'pre':
tag.insert_before('\n\n')
tag.insert_after('\n\n')
tag.insert_before('\n\n```\n')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause any <pre> element to be surrounded with a code fence, not just <pre><code>.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For safety and clarity that's not bad, but makes it harder to convert back to html.

Maybe for <pre> we only indent as you already did, but for <code> we backtick explicitly? Then the process to reverse back to html has a method it can follow.

Comment thread html2markdown.py
@@ -233,7 +233,6 @@ def _markdownify(tag, _listType=None, _blockQuote=False, _listIndex=1):
lines.pop()
for i,line in enumerate(lines):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop doesn't do anything. I can't remember if lines[i] = line.replace(...) is still necessary, but it's currently not being assigned to lines[i].

@unexceptable
Copy link
Copy Markdown

unexceptable commented Nov 11, 2020

@dlon

Thanks! I'm not necessarily opposed to the idea. Fenced code blocks are an extension of standard markdown, though, so it may have to be an option.

Unlike other formats markdown doesn't really have an 'official' spec, and fenced code blocks are kinda of the standard across almost all users of markdown for code.

If anything https://commonmark.org/ is probably 'the standard', and does have fenced back tick codeblocks as part of it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants