Skip to content

Commit

Permalink
markdown: Fix bullet list indentation bug.
Browse files Browse the repository at this point in the history
Previously, the frontend-only javascript processor didn't show the
same output as the backend for unordered lists in case of odd
indentation before the bullet indicator, resulting in wrong output
shown in drafts. This is because their was no specific way to handle
odd indentation.

Fix for it was to check for odd indentation whenever bullet list is
encountered and trim a space to make it even and ideal for zulip's
markdown.

Fixes zulip#10966
  • Loading branch information
AsociTon committed Apr 11, 2019
1 parent 62f2396 commit f361400
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions static/third/marked/lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ Lexer.prototype.token = function(src, top, bq) {
src = src.substring(cap[0].length);
bull = cap[2];

// Reduces the odd number of spaces
// to even.
cap[0] = cap[0].replace(/^(( )*) ?/gm, "$1");

this.tokens.push({
type: 'list_start',
ordered: bull.length > 1
Expand Down
6 changes: 6 additions & 0 deletions zerver/tests/fixtures/markdown_test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@
"marked_expected_output": "<ul>\n<li>I am outer list<br>\nI am something inside</li>\n</ul>",
"text_content": "\nI am outer list\n I am something inside\n"
},
{
"name": "ulist_nested_ulist_with_odd_even_space_indent",
"input": "Nested list\n* I am outer list first item\n * I am outer list second item\n * I am inner nested list first item",
"expected_output": "<p>Nested list</p>\n<ul>\n<li>I am outer list first item</li>\n<li>I am outer list second item<ul>\n<li>I am inner nested list first item</li>\n</ul>\n</li>\n</ul>",
"text_content": "Nested list\n\nI am outer list\nI am inner nested list first item\nI am inner nested list second item\n\n\n"
},
{
"name": "ulist_codeblock",
"input": "~~~\nint x = 3\n* 4;\n~~~",
Expand Down

0 comments on commit f361400

Please sign in to comment.