Commit Graph

62 Commits

Author SHA1 Message Date
Sam Atkins
aea4fbdd7b LibMarkdown: Allow extra content to be inserted into HTML output's head
This lets users supply custom styling and scripting, among other things.
2022-09-28 23:58:26 +01:00
demostanis
68c6161f25 LibMarkdown: Add newline and remove ANSI escape after code blocks
Also make clang-tidy happy by making line a const&
2022-09-01 23:36:23 +00:00
demostanis
1ce23eb640 LibMarkdown: Fix coloring of the first line
The escape sequence to color a section's name was separated
by a newline from the section's name, making less(1) trim
the escape sequence off when the section's name was on the
first line.
2022-08-04 16:57:26 +00:00
demostanis
55b7f8ab27 LibMarkdown: Indent code blocks 2022-08-04 16:57:26 +00:00
MacDue
8140b1fa18 LibMarkdown: Implement the image size extension
This implements the image size extension that's quite commonly used:
https://github.com/commonmark/commonmark-spec/wiki/Deployed-Extensions#image-size

This supports specifying...

Both width and height: ![](foo.png =100x200)
Width only: ![](foo.png =100x)
Height only: ![](foo.png =x200)

The size is always in pixels (relative sizing does not seem
to be spec'd anywhere).
2022-08-04 02:49:29 +02:00
sin-ack
c8585b77d2 Everywhere: Replace single-char StringView op. arguments with chars
This prevents us from needing a sv suffix, and potentially reduces the
need to run generic code for a single character (as contains,
starts_with, ends_with etc. for a char will be just a length and
equality check).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
huttongrabiel
25970f2763 LibMarkdown: Add strike-through text support to markdown
Using ~~text~~ syntax will strike out the text between the two tildes.

Only missing portion is the terminal rendering of strike through text.
The ansi escape codes for strike through text are \e[9m and \e[29m but
it appears the terminal does not support these. Please correct me if I
am wrong.

I tested that the render_to_terminal function was being called by giving
it bold ANSI escape codes, and that did work so the function is being
called correctly.
2022-04-28 22:15:08 +02:00
huttongrabiel
1e65e916fc LibMarkdown: Correct typo in forward declaration of HorizontalRule
HoriziontalRule -> HorizontalRule
2022-04-26 23:23:36 -07:00
Peter Elliott
5847d326c3 LibMarkdown: Treat whitespace-only lines as blank in paragraphs 2022-04-26 15:02:26 +02:00
Peter Elliott
aef5aac772 LibMarkdown: Don't put a newline in empty code blocks
This doesn't actually matter, but I'm trying to match the commonmark
test cases where possible.
2022-04-26 15:02:26 +02:00
Peter Elliott
e084e1ced6 LibMarkdown: Better support for code fences
- Support tildes.
- Support different lengths of fence.
- Begrudgingly keep support for serenities one markdown extension.
2022-04-26 15:02:26 +02:00
Peter Elliott
4d3454d700 LibMarkdown: Support up to 3 spaces before an ATX header 2022-04-26 15:02:26 +02:00
Peter Elliott
116e0dc4de LibMarkdown: Limit headings to 6 levels 2022-04-26 15:02:26 +02:00
Peter Elliott
c15c57a6af LibMarkdown: Make thematic break parsing more correct
also fix a conflict with lists and thematic breaks
2022-04-26 15:02:26 +02:00
Peter Elliott
5ad44ac2e5 LibMarkdown: Ignore backslash on non-punctuation characters 2022-04-26 15:02:26 +02:00
Peter Elliott
0270e23997 LibMarkdown: Add support for indented code blocks 2022-04-26 15:02:26 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Lenny Maiorani
dd08e84664 Libraries: Use default constructors/destructors in LibMarkdown
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-13 22:34:38 +01:00
xSlendiX
7685d53654 LibMarkdown: Add terminal color formatting
This patch adds color formatting to markdown viewed in the terminal.
This also increases readability.
2022-02-17 19:54:47 +01:00
xSlendiX
5d219ad4f7 LibMarkdown: Add additional spacing for terminal rendering
This patch adds spacing to give a sense of structure to markdown
documents viewed in the terminal. This also makes the content easier
to read.
2022-02-17 19:54:47 +01:00
mjz19910
10ec98dd38 Everywhere: Fix spelling mistakes 2022-01-07 15:44:42 +01:00
Sam Atkins
93ef8c8080 LibMarkdown: Output alignment when rendering HTML tables
Previously, only terminal output aligned table column contents
correctly. Now, we apply a `text-align` to each cell. This does not
actually *work* however, since LibWeb's table layout code is not yet
fully functional.
2022-01-06 08:22:46 +03:30
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling
409b20e316 LibMarkdown: Allow nested links
This fixes an issue where the linked images in our README.md didn't
get turned into images.
2021-11-03 10:21:50 +01:00
Ben Wiederhake
d2f9fee4ab LibMarkdown: Recognize and handle comments
This also improves Commonmark coverage, e.g. it fixes tests
HTML_blocks_ex179_2894..2906 and Lists_ex308_5439..5457.

In other words, we go from 271 out of 652 to 273 out of 652.
2021-11-01 21:12:58 +01:00
Ben Wiederhake
24e7196158 LibMarkdown: Implement introspection of the document tree 2021-10-10 15:18:55 -07:00
Ben Wiederhake
aca01932bd LibMarkdown: Make href always a String
This already was the case in some sense, but made it very inconvenient
to access it.
2021-10-10 15:18:55 -07:00
David Isaksson
88eb7a634f LibMarkdown: Have one newline between lists in terminal renders
Before this patch the markdown lists would have two space inbetween each
item. This patch removes one of these newlines for a nicer render.
2021-10-09 12:05:38 +02:00
Peter Elliott
e02c843af4 LibMarkdown: Add blockquotes 2021-10-06 12:35:46 +02:00
Peter Elliott
2227a80f34 LibMarkdown: Add blockquote support to LineIterator
This patch adds contexts to line iterator for nesting list items and
blockquotes. It also incidentally makes the api for LineIterator
simpler, and will make it easier to add other containers in the future.
2021-10-06 12:35:46 +02:00
Peter Elliott
285038ebcf LibMarkdown: Add start numbers for ordered lists
5. hey -> <ol start="5"><li>hey</li></ol>
2021-10-05 13:27:25 +03:30
Peter Elliott
a76a23e33b LibMarkdown: Allow spaces before list items
also allow '+' as an unordered list marker
2021-10-05 13:27:25 +03:30
Peter Elliott
0a21c2bace LibMarkdown: Implement "tightness" for lists
From the commonmark spec:
A list is loose if any of its constituent list items are separated by
blank lines, or if any of its constituent list items directly contain
two block-level elements with a blank line between them. Otherwise a
list is tight. (The difference in HTML output is that paragraphs in a
loose list are wrapped in <p> tags, while paragraphs in a tight list are
not.)
2021-10-05 13:27:25 +03:30
Peter Elliott
5bb87c630c LibMarkdown: Allow non-text items in Lists 2021-10-05 13:27:25 +03:30
Peter Elliott
10f6f6a723 LibMarkdown: Add LineIterator
LineIterator wraps a vector's ConstIterator, to provide an iterator that
can work on indented container blocks (like lists and blockquotes).
2021-10-05 13:27:25 +03:30
Peter Elliott
cd560d3ae3 LibMarkdown: Refactor Document's parser into ContainerBlock
This will better allow us too do things like have Lists and blockquotes
support multiple blocks.
2021-10-05 13:27:25 +03:30
Nico Weber
61e9e80232 LibMarkdown: Fix typo in variable name 2021-10-01 01:33:43 +01:00
Nico Weber
de72332920 Libraries: Fix typos 2021-10-01 01:06:40 +01:00
Peter Elliott
6ae1a80583 LibMarkdown: Re-add support for Serenity's style code blocks extension
I decided to not use the text parser for this one and rely on a regex to
parse the style tags. This way it supports only and opening delimiter
run and also is much simpler.
2021-09-12 12:17:16 +02:00
Peter Elliott
565b561522 LibMarkdown: Render sequences of spaces properly in the terminal 2021-09-12 12:17:16 +02:00
Peter Elliott
9c0563cc10 LibMarkdown: Implement hard and soft line breaks
Hard line breaks insert a <br /> when two spaces are at the end of a
line. soft line breaks are just regular newlines, but whitespace is now
stripped before and after them
2021-09-12 12:17:16 +02:00
Peter Elliott
af5a07399e LibMarkdown: Handle delimiter flanking with punctuation
This patch handles the following two rules
1) A delimiter run is either (a) not followed by a Unicode punctuation
   character, or (b) followed by a Unicode punctuation character and
   preceded by Unicode whitespace or a Unicode punctuation character.

2) A _ can be used to open/close a delimiter run if it's (a) not part
   of a left-flanking delimiter run or (b) part of a left-flanking
   delimiter run followed by a Unicode punctuation character.
2021-09-12 12:17:16 +02:00
Peter Elliott
6724d6d391 LibMarkdown: Add terminal rendering for new markdown Text parser 2021-09-12 12:17:16 +02:00
Peter Elliott
ec9f892899 LibMarkdown: Rewrite Inline text parser to be more forgiving
The previous Text::parse was not able to give up on parsing a textual
element, and just leave it as plain text. Because this is a very
important part of markdown, I fully rewrote the parser to support this
without having to backtrack. Also the parser now some other little
features, such ast delimiter runs and flanking.
2021-09-12 12:17:16 +02:00
Peter Elliott
dee84113ab LibMarkdown: Match HTML formatting of Commonmark tests
This patch changes the HTML formatting (where to put newlines, etc...)
to better match commonmark's test cases. This has minimal effect of the
correctness of our markdown implementation, but makes it easier to test.

Changes:
 - Use <em> instead of <i>.
 - Newline before end of code block.
 - <hr /> instead of <hr>.
 - Newline before first list item.
 - Newline between lines of a paragraph.
 - Trim whitespace on lines of paragraphs.

 Tests passed: 33/652 -> 87/652
2021-08-31 16:53:51 +02:00
Peter Elliott
57ec19f963 LibMarkdown: Add render_to_inline_html() to Document
This api is useful when you want to render a markdown document to HTML,
but you want to embed it in a existing html document.
2021-08-31 16:53:51 +02:00
Sam Atkins
a8946eb888 LibMarkdown: Wrap non-inline code blocks in <pre>
This fixes #7131

The parser already distinguishes between inline code (handled in
Text.cpp) and triple-tick code blocks, so only
CodeBlock::render_to_html() needed to change. Blank lines within
a code block still cause issues, but that's an HTML issue. (#7121)
2021-06-09 18:06:54 +01:00
Linus Groh
9c19e62675 LibMarkdown: Wrap code block language string in escape_html_entities()
This would allow HTML injection as the string was inserted into the HTML
output with no sanitation whatsoever.

Fixes #7123.
2021-05-19 23:31:00 +01:00
Andreas Kling
730ed465fe LibMarkdown: Convert StringBuilder::appendf() => AK::Format
These are the last ones in the codebase. :^)
2021-05-07 21:12:09 +02:00