|
1 | 1 | # @portabletext/markdown |
2 | 2 |
|
| 3 | +## 2.0.1 |
| 4 | + |
| 5 | +### Patch Changes |
| 6 | + |
| 7 | +- [#3183](https://github.com/portabletext/editor/pull/3183) [`0da0721`](https://github.com/portabletext/editor/commit/0da07219dc83b0cb7b545a45519b2c62c7b70737) Thanks [@christianhg](https://github.com/christianhg)! - fix: escape markdown syntax in plain span text during serialization |
| 8 | + |
| 9 | + If your Portable Text contains text that happens to look like markdown, converting it to markdown and back used to corrupt it: the punctuation was read as formatting instead of text. `portableTextToMarkdown` now backslash-escapes such text, so it comes back as exactly the text it was. |
| 10 | + |
| 11 | + ```ts |
| 12 | + // span text markdown (before) markdown (now) re-parses as |
| 13 | + '*bar*' // *bar* \*bar\* the text `*bar*` (was: an emphasized span reading `bar`) |
| 14 | + '# heading' // # heading \# heading the text `# heading` (was: an `h1` block) |
| 15 | + '[x]: y' // [x]: y \[x]: y the text `[x]: y` (was: nothing, the line vanished) |
| 16 | + ``` |
| 17 | + |
| 18 | + This works wherever the text sits (headings, blockquotes, list items, table cells) and also when the risky characters are split across neighboring spans. The visible change in your output: markdown for text containing such punctuation gains backslashes it didn't have before. It pastes and parses like any hand-written markdown. |
| 19 | + |
| 20 | + Text with the `code` decorator is never backslash-escaped. Its backtick delimiters widen instead, so the content survives verbatim even when it contains backticks: |
| 21 | + |
| 22 | + ```ts |
| 23 | + // span text with the `code` decorator markdown (before) markdown (now) |
| 24 | + 'a`b' // `a`b` (broken) ``a`b`` |
| 25 | + '`a' // ``a` (broken) `` `a `` |
| 26 | + ``` |
| 27 | + |
| 28 | + If you supply custom mark or block renderers: `children` now arrives pre-escaped. When you need the original text, read the `text` argument instead (the built-in `code` renderer does exactly that). |
| 29 | + |
| 30 | + Two things stay as they were. A URL with an explicit scheme (`https://…`) or an email address is not escaped: it keeps its text and simply becomes a link on the next parse. A `www.`-style address is only left alone while it contains no markdown punctuation; with it, it gets escaped like ordinary text, and the round trip keeps every character either way. And leading or trailing whitespace that markdown itself trims still trims, same as before this change. |
| 31 | + |
| 32 | +- [#3234](https://github.com/portabletext/editor/pull/3234) [`452fdbe`](https://github.com/portabletext/editor/commit/452fdbea5dfd8a04ced66a8e297e50b5c8c8260c) Thanks [@christianhg](https://github.com/christianhg)! - fix: parse markdown soft breaks as spaces, not line breaks |
| 33 | + |
| 34 | + Markdown written across several source lines, the way editors and prose tools wrap text, is one paragraph that reflows. `markdownToPortableText` used to bake each of those wraps into the text as a literal newline, exactly as if you had written a hard break, and converting back to markdown then produced real hard breaks that weren't in your document. |
| 35 | + |
| 36 | + Wrapped source like this: |
| 37 | + |
| 38 | + ```md |
| 39 | + This paragraph is written |
| 40 | + across two source lines. |
| 41 | + ``` |
| 42 | + |
| 43 | + used to parse to the span text `'This paragraph is written\nacross two source lines.'` (a fixed line break in the content) and now parses to `'This paragraph is written across two source lines.'` (one reflowing line, which is how markdown renders it). |
| 44 | + |
| 45 | + Real hard breaks are unchanged: end a line with two or more spaces, or a backslash, and the span text still gets a `\n`: |
| 46 | + |
| 47 | + ```md |
| 48 | + Line one\ |
| 49 | + Line two |
| 50 | + ``` |
| 51 | + |
| 52 | + still parses to `'Line one\nLine two'`. |
| 53 | + |
3 | 54 | ## 2.0.0 |
4 | 55 |
|
5 | 56 | ### Major Changes |
|
0 commit comments