From 21471d7823f0fc763ea09e707bca71cee267bb61 Mon Sep 17 00:00:00 2001 From: "Zee (ZM)" <114668551+zm-cttae@users.noreply.github.com> Date: Sat, 4 Mar 2023 15:28:52 +0000 Subject: [PATCH 1/5] Update defaults to match Github conventions (closes #424) Refs: #424 --- README.md | 11 ++++++----- src/turndown.js | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 21fba128..18d97636 100644 --- a/README.md +++ b/README.md @@ -50,15 +50,16 @@ var turndownService = new TurndownService({ option: 'value' }) | Option | Valid values | Default | | :-------------------- | :------------ | :------ | -| `headingStyle` | `setext` or `atx` | `setext` | -| `hr` | Any [Thematic break](http://spec.commonmark.org/0.27/#thematic-breaks) | `* * *` | -| `bulletListMarker` | `-`, `+`, or `*` | `*` | -| `codeBlockStyle` | `indented` or `fenced` | `indented` | +| `headingStyle` | `setext` or `atx` | `atx` | +| `hr` | Any [Thematic break](http://spec.commonmark.org/0.27/#thematic-breaks) | `---` | +| `bulletListMarker` | `-`, `+`, or `*` | `-` | +| `codeBlockStyle` | `indented` or `fenced` | `fenced` | | `fence` | ` ``` ` or `~~~` | ` ``` ` | -| `emDelimiter` | `_` or `*` | `_` | +| `emDelimiter` | `_` or `*` | `*` | | `strongDelimiter` | `**` or `__` | `**` | | `linkStyle` | `inlined` or `referenced` | `inlined` | | `linkReferenceStyle` | `full`, `collapsed`, or `shortcut` | `full` | +| `br` | ` ` or `\n` | `\n` | | `preformattedCode` | `false` or [`true`](https://github.com/lucthev/collapse-whitespace/issues/16) | `false` | ### Advanced Options diff --git a/src/turndown.js b/src/turndown.js index ff4a2cb3..ac22f7bf 100644 --- a/src/turndown.js +++ b/src/turndown.js @@ -25,16 +25,16 @@ export default function TurndownService (options) { var defaults = { rules: COMMONMARK_RULES, - headingStyle: 'setext', - hr: '* * *', - bulletListMarker: '*', - codeBlockStyle: 'indented', + headingStyle: 'atx', + hr: '---', + bulletListMarker: '-', + codeBlockStyle: 'fence', fence: '```', - emDelimiter: '_', + emDelimiter: '*', strongDelimiter: '**', linkStyle: 'inlined', linkReferenceStyle: 'full', - br: ' ', + br: '\n', preformattedCode: false, blankReplacement: function (content, node) { return node.isBlock ? '\n\n' : '' From d44d65a75875cfa787edecb671f0338dfa1ad796 Mon Sep 17 00:00:00 2001 From: ZM Date: Thu, 6 Jul 2023 22:01:53 +0100 Subject: [PATCH 2/5] Fix code fencing option typo for #425 Refs: #425, @acnebs --- src/turndown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/turndown.js b/src/turndown.js index ac22f7bf..1d0347fd 100644 --- a/src/turndown.js +++ b/src/turndown.js @@ -28,7 +28,7 @@ export default function TurndownService (options) { headingStyle: 'atx', hr: '---', bulletListMarker: '-', - codeBlockStyle: 'fence', + codeBlockStyle: 'fenced', fence: '```', emDelimiter: '*', strongDelimiter: '**', From d1f75b6434558f4a5ca82df12821bc4c8dc33074 Mon Sep 17 00:00:00 2001 From: ZM Date: Thu, 20 Jul 2023 11:19:59 +0100 Subject: [PATCH 3/5] Revert `options.br` change: hard->soft break Refs: #425, cc @huan086 --- README.md | 2 +- src/turndown.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 18d97636..5a133450 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ var turndownService = new TurndownService({ option: 'value' }) | `strongDelimiter` | `**` or `__` | `**` | | `linkStyle` | `inlined` or `referenced` | `inlined` | | `linkReferenceStyle` | `full`, `collapsed`, or `shortcut` | `full` | -| `br` | ` ` or `\n` | `\n` | +| `br` | ` ` or `\n` | ` ` | | `preformattedCode` | `false` or [`true`](https://github.com/lucthev/collapse-whitespace/issues/16) | `false` | ### Advanced Options diff --git a/src/turndown.js b/src/turndown.js index 1d0347fd..5fe6103b 100644 --- a/src/turndown.js +++ b/src/turndown.js @@ -34,7 +34,7 @@ export default function TurndownService (options) { strongDelimiter: '**', linkStyle: 'inlined', linkReferenceStyle: 'full', - br: '\n', + br: ' ', preformattedCode: false, blankReplacement: function (content, node) { return node.isBlock ? '\n\n' : '' From f1e782842cab48c1b5ece31b903214123a6c16b3 Mon Sep 17 00:00:00 2001 From: zm-cttae <114668551+zm-cttae@users.noreply.github.com> Date: Wed, 17 Jul 2024 19:32:44 +0100 Subject: [PATCH 4/5] Update tests --- package-lock.json | 1 + test/index.html | 171 ++++++++++++++++++++++++---------------------- 2 files changed, 92 insertions(+), 80 deletions(-) diff --git a/package-lock.json b/package-lock.json index 739aa476..0c65ebed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "turndown", "version": "7.1.1", "license": "MIT", "dependencies": { diff --git a/test/index.html b/test/index.html index 26fa586c..31cda74a 100644 --- a/test/index.html +++ b/test/index.html @@ -29,12 +29,12 @@
em element
-
_em element_
+
*em element*
i element
-
_i element_
+
*i element*
@@ -84,8 +84,7 @@

Level One Heading

-
Level One Heading
-=================
+
# Level One Heading
@@ -98,20 +97,21 @@
A sentence containing =
-
-

Level One Heading with ATX

-
# Level One Heading with ATX
+
+

Level One Heading with Setext

+
Level One Heading with Setext
+-----------------------------

Level Two Heading

-
Level Two Heading
------------------
+
## Level Two Heading
-
-

Level Two Heading with ATX

-
## Level Two Heading with ATX
+
+

Level Two Heading with Setext

+
Level Two Heading with Setext
+-----------------------------
@@ -131,17 +131,17 @@

-
* * *
+
---

-
* * *
+
---
-
+

-
- - -
+
* * *
@@ -254,10 +254,12 @@ "Hello world!" end
-
    def code_block
-      # 42 < 9001
-      "Hello world!"
-    end
+
```
+def code_block
+  # 42 < 9001
+  "Hello world!"
+end
+```
@@ -273,17 +275,21 @@ "Hello world!" end
-
    def first_code_block
-      # 42 < 9001
-      "Hello world!"
-    end
+  
```
+def first_code_block
+  # 42 < 9001
+  "Hello world!"
+end
+```
 
 next:
 
-    def second_code_block
-      # 42 < 9001
-      "Hello world!"
-    end
+``` +def second_code_block + # 42 < 9001 + "Hello world!" +end +```
@@ -295,14 +301,15 @@ removed
-
    Multiple new lines
-    
-    
-    should not be
-    
-    
-    removed
-
+
```
+Multiple new lines
+
+
+should not be
+
+
+removed
+```
@@ -399,9 +406,9 @@ Another paragraph. -* Unordered list item 1 -* Unordered list item 2 -* Unordered list item 3 +- Unordered list item 1 +- Unordered list item 2 +- Unordered list item 3
@@ -412,9 +419,9 @@
  • Unordered list item 3
  • -
    *   Unordered list item 1
    -*   Unordered list item 2
    -*   Unordered list item 3
    +
    -   Unordered list item 1
    +-   Unordered list item 2
    +-   Unordered list item 3
    @@ -437,9 +444,9 @@
  • List item without paragraph
  • -
    *   List item with paragraph
    +  
    -   List item with paragraph
         
    -*   List item without paragraph
    +- List item without paragraph
    @@ -482,14 +489,14 @@
  • This is a third item at root level
  • -
    *   This is a list item at root level
    -*   This is another item at root level
    -*   *   This is a nested list item
    -    *   This is another nested list item
    -    *   *   This is a deeply nested list item
    -        *   This is another deeply nested list item
    -        *   This is a third deeply nested list item
    -*   This is a third item at root level
    +
    -   This is a list item at root level
    +-   This is another item at root level
    +-   -   This is a nested list item
    +    -   This is another nested list item
    +    -   -   This is a deeply nested list item
    +        -   This is another deeply nested list item
    +        -   This is a third deeply nested list item
    +-   This is a third item at root level
    @@ -513,14 +520,14 @@
  • This is a third item at root level
  • -
    *   This is a list item at root level
    -*   This is another item at root level
    -*   1.  This is a nested list item
    +  
    -   This is a list item at root level
    +-   This is another item at root level
    +-   1.  This is a nested list item
         2.  This is another nested list item
    -    3.  *   This is a deeply nested list item
    -        *   This is another deeply nested list item
    -        *   This is a third deeply nested list item
    -*   This is a third item at root level
    + 3. - This is a deeply nested list item + - This is another deeply nested list item + - This is a third deeply nested list item +- This is a third item at root level
    @@ -534,7 +541,7 @@
    -
    *   A list item with a blockquote:
    +  
    -   A list item with a blockquote:
         
         > This is a blockquote inside a list item.
    @@ -580,16 +587,16 @@

    This is a header.

    return 1 < 2 ? shell_exec('echo $input | $markdown_script') : 0;
    -
    > This is a header.
    -> -----------------
    +  
    > ## This is a header.
     > 
     > 1.  This is the first list item.
     > 2.  This is the second list item.
     > 
     > A code block:
     > 
    ->     return 1 < 2 ? shell_exec('echo $input | $markdown_script') : 0;
    - +> ``` +> return 1 < 2 ? shell_exec('echo $input | $markdown_script') : 0; +> ```
    @@ -620,7 +627,9 @@

    This is a header.

    Hello world
    -
        Hello world
    +
    ```
    +Hello world
    +```
    @@ -665,10 +674,10 @@

    This is a header.

    -
    *   Indented li with leading/trailing newlines
    -*   **Strong with trailing space inside li with leading/trailing whitespace**
    -*   li without whitespace
    -*   Leading space, text, lots of whitespace … text
    +
    -   Indented li with leading/trailing newlines
    +-   **Strong with trailing space inside li with leading/trailing whitespace**
    +-   li without whitespace
    +-   Leading space, text, lots of whitespace … text
    @@ -680,7 +689,7 @@

    This is a header.

    Text with no space after the period. Text in em with leading/trailing spaces text in strong with trailing space
    -
    Text with no space after the period. _Text in em with leading/trailing spaces_ **text in strong with trailing space**
    +
    Text with no space after the period. *Text in em with leading/trailing spaces* **text in strong with trailing space**
    @@ -744,7 +753,9 @@

    This is a header.

    def this_is_a_method; end;
    -
        def this_is_a_method; end;
    +
    ```
    +def this_is_a_method; end;
    +```
    @@ -829,7 +840,7 @@

    This is a header.

    test_italics
    -
    _test\_italics_
    +
    *test\_italics*
    @@ -1004,42 +1015,42 @@

    This is a header.

    foo bar
    -
    _foo_ bar
    +
    *foo* bar
    foo  bar
    -
    _foo_  bar
    +
    *foo*  bar
    foo  bar
    -
    _foo_  bar
    +
    *foo*  bar
    foo  bar
    -
    _foo_  bar
    +
    *foo*  bar
    foo bar
    -
    foo _bar_
    +
    foo *bar*
    foo  bar
    -
    foo  _bar_
    +
    foo  *bar*
    foo  bar
    -
    foo  _bar_
    +
    foo  *bar*
    foo  bar
    -
    foo  _bar_
    +
    foo  *bar*
    From bb369b639c78e2939a1b19b8ffc888507a402f2b Mon Sep 17 00:00:00 2001 From: zm-cttae <114668551+zm-cttae@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:02:23 +0000 Subject: [PATCH 5/5] Fix test for level 1 setext --- test/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.html b/test/index.html index 31cda74a..5e890171 100644 --- a/test/index.html +++ b/test/index.html @@ -100,7 +100,7 @@

    Level One Heading with Setext

    Level One Heading with Setext
    ------------------------------
    +=============================