Skip to content

Commit

Permalink
🐛 Fix the github slugify mode (#792) (#817)
Browse files Browse the repository at this point in the history
## Summary

* ⬆ Update dependencies
  * Enable new language features:
    * ts-loader: 6.2.2 -> 8.0.3
    * typescript: 3.5.2 -> 4.0.2
  * Improve HTML entities decoding:
    * entities: 2.0.0 -> 2.0.3
  * Improve syntax highlighting when printing:
    * highlight.js: 9.15.6 -> 10.2.0
    * @types/highlight.js: 9.12.3 -> 9.12.4
  * Others are just regular upgrades.
* 🎨 Refactor function `slugify`
  * Move all the slugify functions to `slugifyMethods`.
  * Add a few comments.
* 🐛 Perform user-required case conversion before calling slugify function
* 🎨 Add type annotations to `markdownEngine.ts`
* ✨ Add `CommonmarkEngine`
* 🐛 Fix the `github` slugify function
  * Use `commonmarkEngine.engine.renderInline()`.
  * Use `entities.decodeHTML()` to decode HTML entities.
  * Correct `getTextInHtml()`.
  * Correct `PUNCTUATION_REGEXP`.
  * Add "Perform full Unicode case conversion".
* 🎨 Optimize the `gitlab` slugify function
* 🔧 Reorganize vscodeignore
* 🔧 Update metadata
  * `categories`.
  * Description of configuration.
* ✅ Correct unit test
* 👷 Allow to run CI manually

## Known issues

1. "Printing" may not generate correct heading ID.

Failed cases:

```markdown
## `<em>code</em>`
## 😅
```

The second case is related to `markdown-it-emoji`. See
#809 (comment)

2. Some headings may lead to weird TOC text. Links are not affected. For example:

a][b

Co-authored-by: Lemmingh <43396014+Lemmingh@users.noreply.github.com>
  • Loading branch information
yzhang-gh and Lemmingh authored Sep 16, 2020
1 parent faa18bd commit b5b9ebf
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 215 deletions.
72 changes: 35 additions & 37 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'

# Runs a set of commands using the runners shell
- name: Install
run: |
npm install
npm install -g vsce
- name: Build
run: vsce package

- name: Test
uses: GabrielBB/xvfb-action@v1.0
with:
run: npm test

- name: Upload artifact
uses: actions/upload-artifact@v2-preview
with:
name: Markdown-all-in-one-GitHub-Build
path: ./*.vsix
- uses: actions/checkout@v2

- name: "Setup Node.js environment"
uses: actions/setup-node@v1
with:
node-version: "12"

- name: "Install dependencies"
run: |
npm ci
npm install -g vsce
- name: Build
run: vsce package

- name: Test
uses: GabrielBB/xvfb-action@v1.0
with:
run: npm test

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: Markdown-All-in-One-${{ github.sha }}
path: ./*.vsix

- name: "(debug) Upload npm log"
if: ${{ !success() }}
uses: actions/upload-artifact@v2
with:
name: "npm-debug-log"
path: "~/.npm/_logs"
18 changes: 13 additions & 5 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
.vscode/**
.vscode-test/**
out/test/**
src/**
# Important: The patterns are relative to the location of the vscodeignore file.

# Development tools, intermediate build results, and temporary files
.vscode-test/
out/
tools/
**/*.map
.github/**

# Source files
src/
**/*.ts

# Configuration files
.github/
.vscode/
VERSION
.gitignore
tsconfig.json
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 40 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"vscode": "^1.38.0"
},
"categories": [
"Programming Languages",
"Formatters",
"Other"
],
"keywords": [
Expand Down Expand Up @@ -228,7 +230,7 @@
"markdown.extension.italic.indicator": {
"type": "string",
"default": "*",
"description": "%config.italic.indicator.description%",
"markdownDescription": "%config.italic.indicator.description%",
"enum": [
"*",
"_"
Expand Down Expand Up @@ -271,7 +273,7 @@
"one",
"ordered"
],
"enumDescriptions": [
"markdownEnumDescriptions": [
"%config.orderedList.marker.enumDescriptions.one%",
"%config.orderedList.marker.enumDescriptions.ordered%"
]
Expand All @@ -293,17 +295,17 @@
"description": "%config.print.imgToBase64.description%",
"scope": "resource"
},
"markdown.extension.print.includeVscodeStylesheets": {
"type": "boolean",
"default": true,
"description": "%config.print.includeVscodeStylesheets%"
},
"markdown.extension.print.onFileSave": {
"type": "boolean",
"default": false,
"description": "%config.print.onFileSave.description%",
"scope": "resource"
},
"markdown.extension.print.validateUrls": {
"type": "boolean",
"default": true,
"description": "%config.print.validateUrls.description%"
},
"markdown.extension.print.theme": {
"type": "string",
"default": "light",
Expand All @@ -314,10 +316,10 @@
"description": "%config.print.theme%",
"scope": "resource"
},
"markdown.extension.print.includeVscodeStylesheets": {
"markdown.extension.print.validateUrls": {
"type": "boolean",
"default": true,
"description": "%config.print.includeVscodeStylesheets%"
"description": "%config.print.validateUrls.description%"
},
"markdown.extension.syntax.decorations": {
"type": "boolean",
Expand All @@ -332,7 +334,7 @@
"markdown.extension.syntax.plainTheme": {
"type": "boolean",
"default": false,
"description": "%config.syntax.plainTheme.description%"
"markdownDescription": "%config.syntax.plainTheme.description%"
},
"markdown.extension.tableFormatter.enabled": {
"type": "boolean",
Expand All @@ -342,28 +344,22 @@
"markdown.extension.tableFormatter.normalizeIndentation": {
"type": "boolean",
"default": false,
"description": "%config.tableFormatter.normalizeIndentation.description%"
"markdownDescription": "%config.tableFormatter.normalizeIndentation.description%"
},
"markdown.extension.toc.downcaseLink": {
"type": "boolean",
"default": true,
"description": "%config.toc.downcaseLink.description%"
},
"markdown.extension.toc.slugifyMode": {
"type": "string",
"default": "github",
"enum": [
"github",
"gitlab",
"gitea",
"vscode"
],
"description": "%config.toc.slugifyMode.description%"
"markdownDescription": "%config.toc.downcaseLink.description%"
},
"markdown.extension.toc.levels": {
"type": "string",
"default": "1..6",
"description": "%config.toc.levels.description%"
"markdownDescription": "%config.toc.levels.description%"
},
"markdown.extension.toc.omittedFromToc": {
"type": "object",
"default": {},
"description": "%config.toc.omittedFromToc.description%"
},
"markdown.extension.toc.orderedList": {
"type": "boolean",
Expand All @@ -375,10 +371,27 @@
"default": false,
"description": "%config.toc.plaintext.description%"
},
"markdown.extension.toc.slugifyMode": {
"type": "string",
"default": "github",
"markdownDescription": "%config.toc.slugifyMode.description%",
"enum": [
"github",
"gitea",
"gitlab",
"vscode"
],
"enumDescriptions": [
"GitHub",
"Gitea",
"GitLab",
"Visual Studio Code"
]
},
"markdown.extension.toc.unorderedList.marker": {
"type": "string",
"default": "-",
"description": "%config.toc.unorderedList.marker.description%",
"markdownDescription": "%config.toc.unorderedList.marker.description%",
"enum": [
"-",
"*",
Expand All @@ -389,11 +402,6 @@
"type": "boolean",
"default": true,
"description": "%config.toc.updateOnSave.description%"
},
"markdown.extension.toc.omittedFromToc": {
"type": "object",
"default": {},
"description": "%config.toc.omittedFromToc.description%"
}
}
},
Expand Down Expand Up @@ -442,10 +450,10 @@
},
"devDependencies": {
"@types/highlight.js": "^9.12.4",
"@types/image-size": "^0.8.0",
"@types/image-size": "^0.7.0",
"@types/markdown-it": "^10.0.2",
"@types/mocha": "^5.2.6",
"@types/node": "^14.10.1",
"@types/node": "^12.12.58",
"@types/vscode": "1.38.0",
"glob": "^7.1.6",
"mocha": "^7.1.1",
Expand Down
67 changes: 33 additions & 34 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,38 @@
"command.editing.toggleList.title": "Toggle list",
"command.editing.toggleCodeBlock.title": "Toggle code block",
"config.title": "Markdown All in One",
"config.toc.levels.description": "Range of levels for table of contents. Use `x..y` for level x to y",
"config.toc.orderedList.description": "Use ordered list (1. ..., 2. ...)",
"config.toc.unorderedList.marker.description": "Use `-`, `*` or `+` in the table of contents (for unordered list)",
"config.toc.plaintext.description": "Just plain text",
"config.toc.updateOnSave.description": "Auto update on save",
"config.toc.githubCompatibility.description": "(Deprecated) GitHub compatibility (use `slugifyMode: 'github' instead`)",
"config.toc.slugifyMode.description": "Slugify mode for TOC link generation",
"config.toc.downcaseLink.description": "Whether to downcase TOC links",
"config.toc.omittedFromToc.description": "Lists of headings to omit by project file (e.g. {\"README.md\": [\"# Introduction\"]})",
"config.list.indentationSize.description": "Whether to use different indentation sizes on different contexts. (This also affects the generated TOC)",
"config.list.indentationSize.enumDescriptions.adaptive": "Use 2 spaces for unordered list and 3 for the ordered",
"config.list.indentationSize.enumDescriptions.inherit": "Use the configured tab size of the current document (see vscode status bar)",
"config.math.enabled": "Enable basic math support (with KaTeX)",
"config.preview.autoShowPreviewToSide.description": "Auto show preview to side",
"config.orderedList.marker.description": "Ordered list marker",
"config.orderedList.marker.enumDescriptions.one": "Always use `1.` as ordered list marker",
"config.orderedList.marker.enumDescriptions.ordered": "Use increasing numbers as ordered list marker",
"config.orderedList.autoRenumber.description": "Auto fix ordered list markers",
"config.italic.indicator.description": "Use `*` or `_` to wrap italic text",
"config.tableFormatter.enabled.description": "Enable GFM table formatter",
"config.tableFormatter.normalizeIndentation.description": "Normalize table indentation to closest multiple of configured tabSize",
"config.print.absoluteImgPath.description": "Convert image path to absolute path",
"config.print.imgToBase64.description": "Convert images to base64 when printing to HTML",
"config.print.onFileSave.description": "Print current document to HTML when file is saved",
"config.print.validateUrls.description": "Enable/disable URL validation when printing",
"config.print.theme": "Theme of the exported HTML",
"config.print.includeVscodeStylesheets": "Include VSCode's basic Markdown styles so that the exported HTML looks similar as inside VSCode",
"config.syntax.decorations.description": "Add syntax decorations (e.g. ~~strikethrough~~, `code span`)",
"config.syntax.decorationFileSizeLimit.description": "If a file is larger than this size (in byte/B), we shouldn't attempt to render syntax decorations",
"config.syntax.plainTheme.description": "Only take effect when `extension.syntax.decorations` is enabled",
"config.katex.macros.description": "User-defined KaTeX macros",
"config.completion.root": "The root folder for path auto-completion",
"config.completion.respectVscodeSearchExclude": "Whether to exclude files from auto-completion using VSCode's `search.exclude` option. (`node_modules`, `bower_components` and `*.code-search` are always excluded, not affected by this option.)",
"config.completion.respectVscodeSearchExclude": "Whether to exclude files from auto-completion using VS Code's `search.exclude` setting. (`node_modules`, `bower_components` and `*.code-search` are **always excluded**, not affected by this option.)",
"config.completion.root": "The root folder for path auto-completion.",
"config.italic.indicator.description": "Use `*` or `_` to wrap italic text.",
"config.katex.macros.description": "User-defined KaTeX macros.",
"config.list.indentationSize.description": "List indentation scheme. Whether to use different indentation sizes on different list contexts or a user-defined value. (This also affects TOC generation.)",
"config.list.indentationSize.enumDescriptions.adaptive": "Use 2 spaces for unordered list and 3 for the ordered.",
"config.list.indentationSize.enumDescriptions.inherit": "Use the configured tab size of the current document. (See VS Code's status bar)",
"config.math.enabled": "Enable basic math support (Powered by KaTeX).",
"config.orderedList.autoRenumber.description": "Auto fix ordered list markers.",
"config.orderedList.marker.description": "Ordered list marker.",
"config.orderedList.marker.enumDescriptions.one": "Always use `1.` as ordered list marker.",
"config.orderedList.marker.enumDescriptions.ordered": "Use increasing numbers as ordered list marker.",
"config.preview.autoShowPreviewToSide.description": "Auto show preview to side.",
"config.print.absoluteImgPath.description": "Convert image path to absolute path.",
"config.print.imgToBase64.description": "Convert images to base64 when printing to HTML.",
"config.print.includeVscodeStylesheets": "Include VS Code's basic Markdown styles so that the exported HTML looks similar as inside VS Code.",
"config.print.onFileSave.description": "Print current document to HTML when file is saved.",
"config.print.theme": "Theme of the exported HTML. Only affects code blocks.",
"config.print.validateUrls.description": "Enable/disable URL validation when printing.",
"config.syntax.decorations.description": "Add syntax decorations in editors. (e.g. ~~strikethrough~~, `code span`)",
"config.syntax.decorationFileSizeLimit.description": "If a file is larger than this size (in byte/B), we won't attempt to render syntax decorations.",
"config.syntax.plainTheme.description": "Only take effect when `extension.syntax.decorations` is enabled.",
"config.tableFormatter.enabled.description": "Enable GitHub Flavored Markdown table formatter.",
"config.tableFormatter.normalizeIndentation.description": "Normalize table indentation to closest multiple of configured `tabSize`.",
"config.toc.downcaseLink.description": "Whether to **force** to downcase TOC links.",
"config.toc.levels.description": "Range of levels for table of contents. Use `x..y` for level `x` to `y`.",
"config.toc.omittedFromToc.description": "Lists of headings to omit by project file.\nExample:\n{ \"README.md\": [\"# Introduction\"] }",
"config.toc.orderedList.description": "Use ordered list, that is:\n1. ...\n2. ...",
"config.toc.plaintext.description": "Just plain text TOC, no links.",
"config.toc.slugifyMode.description": "The method to generate heading ID. This affects **links to headings** in **TOC**, **code completion**, and **printing**.",
"config.toc.unorderedList.marker.description": "Use `-`, `*`, or `+` in the table of contents (for **unordered** list).",
"config.toc.updateOnSave.description": "Auto update TOC on save.",
"showMe": "Show Me",
"dismiss": "Dismiss",
"noValidMarkdownFile": "No valid Markdown file",
Expand All @@ -62,4 +61,4 @@
"2.1.0 msg": "Markdown All in One v2.1.0! Paste URL as link, multi-cursor support, and more.",
"2.4.0 msg": "Markdown All in One v2.4.0! New command 'toggleList' and KaTeX macros support.",
"3.0.0 msg": "Markdown All in One v3.0.0! New command 'add section numbers' and better compatibility with other Markdown syntax extensions."
}
}
Loading

0 comments on commit b5b9ebf

Please sign in to comment.