Skip to content

Commit

Permalink
fix github header id generation compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vsch committed Apr 12, 2020
1 parent d8a76e5 commit 016b65b
Show file tree
Hide file tree
Showing 29 changed files with 891 additions and 73 deletions.
16 changes: 15 additions & 1 deletion VERSION-TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ Please give feedback on the upcoming changes if you have concerns about breaking

## 0.61.6

* Add: `HtmlRenderer.HEADER_ID_REF_TEXT_TRIM_LEADING_SPACES` default `true` and
`HtmlRenderer.HEADER_ID_REF_TEXT_TRIM_TRAILING_SPACES` default `true`. When `false` then
corresponding reference link text in heading text used for generating heading id is not
trimmed.
* Add: `HtmlRenderer.HEADER_ID_ADD_EMOJI_SHORTCUT` default `false` When `true` then emjoi nodes
add emoji shortcut to collected text for heading id.
* Fix: `ParserEmulationProfile.GITHUB`
* Set `HtmlRenderer.HEADER_ID_REF_TEXT_TRIM_TRAILING_SPACES` to `false` because GitHub does
not trim trailing spaces for generating heading ids.
* `Emoji` node to generate text for heading id consisting of the emoji shortcut, for GitHub
compatibility.
* Fix: `ImageRef` not to add text to heading text for heading id generation
* Fix: add more information to `MarkdownParagraph.resolveTrackedOffsetsEdit` assert failures to
allow better diagnostics in reported stack traces.
* Fix: disable wrapping of multiline URL image links
Expand All @@ -227,11 +239,13 @@ Please give feedback on the upcoming changes if you have concerns about breaking
parsing.
* Fix: `TablesExtension` to accept non-indenting leading spaces on all table rows. This
results in previously non-table text as valid table texts:

```markdown
Abc|Def
|---|---
```
* Fix: `LinkRef` and `ImageRef` changing spaces to ` ` for wrap formatting when not part of
a `Paragraph`, ie. in heading text.

## 0.61.4

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.vladsch.flexmark.core.test.util.renderer;

import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.test.util.spec.ResourceLocation;
import com.vladsch.flexmark.test.util.spec.SpecExample;
import com.vladsch.flexmark.util.data.DataHolder;
import com.vladsch.flexmark.util.data.MutableDataSet;
import org.jetbrains.annotations.NotNull;
import org.junit.runners.Parameterized;

import java.util.List;

final public class ComboExtraSpec2Test extends CoreRendererSpecTest {
final private static String SPEC_RESOURCE = "/core_extra_ast_spec2.md";
final public static @NotNull ResourceLocation RESOURCE_LOCATION = ResourceLocation.of(SPEC_RESOURCE);

final private static DataHolder OPTIONS = new MutableDataSet()
.set(HtmlRenderer.PERCENT_ENCODE_URLS, true)
.toImmutable();

public ComboExtraSpec2Test(@NotNull SpecExample example) {
super(example, null, OPTIONS);
}

@Parameterized.Parameters(name = "{0}")
public static List<Object[]> data() {
return getTestData(RESOURCE_LOCATION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ public abstract class CoreRendererSpecTest extends RendererSpecTest {
static {
ArrayList<String> userTags = new ArrayList<>(Parser.HTML_BLOCK_TAGS.get(null));
userTags.add("tag");
optionsMap.put("heading-ids", new MutableDataSet().set(HtmlRenderer.RENDER_HEADER_ID, true));
optionsMap.put("heading-ids-no-dupe-dashes", new MutableDataSet().set(HtmlRenderer.HEADER_ID_GENERATOR_NO_DUPED_DASHES, true));
optionsMap.put("heading-ids-no-non-ascii-lowercase", new MutableDataSet().set(HtmlRenderer.HEADER_ID_GENERATOR_NON_ASCII_TO_LOWERCASE, false));
optionsMap.put("heading-ids-no-trim-start", new MutableDataSet().set(HtmlRenderer.HEADER_ID_REF_TEXT_TRIM_LEADING_SPACES, false));
optionsMap.put("heading-ids-no-trim-end", new MutableDataSet().set(HtmlRenderer.HEADER_ID_REF_TEXT_TRIM_TRAILING_SPACES, false));
optionsMap.put("heading-ids-emoji", new MutableDataSet().set(HtmlRenderer.HEADER_ID_ADD_EMOJI_SHORTCUT, true));
optionsMap.put("heading-ids-github", new MutableDataSet()
.set(HtmlRenderer.HEADER_ID_GENERATOR_TO_DASH_CHARS, " -")
.set(HtmlRenderer.HEADER_ID_GENERATOR_NON_DASH_CHARS, "_")
.set(HtmlRenderer.HEADER_ID_GENERATOR_NON_ASCII_TO_LOWERCASE, false)

// GitHub does not trim trailing spaces of Ref Links in Headings for ID generation
.set(HtmlRenderer.HEADER_ID_REF_TEXT_TRIM_TRAILING_SPACES, false)
// GitHub adds emoji shortcut text to heading id
.set(HtmlRenderer.HEADER_ID_ADD_EMOJI_SHORTCUT, true)
);

optionsMap.put("user-block-tags", new MutableDataSet().set(Parser.HTML_BLOCK_TAGS, userTags));
optionsMap.put("obfuscate-email", new MutableDataSet().set(HtmlRenderer.OBFUSCATE_EMAIL, true));
optionsMap.put("keep-blank-lines", new MutableDataSet().set(Parser.BLANK_LINES_IN_AST, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@RunWith(Suite.class)
@Suite.SuiteClasses({
ComboExtraSpecTest.class,
ComboExtraSpec2Test.class,
CoreCompatibilityTestSuite.class,
ComboIssuesSpecTest.class,
FullOrigSpecCoreTest.class,
Expand Down
Loading

0 comments on commit 016b65b

Please sign in to comment.