Skip to content

Commit

Permalink
Merge pull request #11 from marp-team/fix-math-collision-mdallinone
Browse files Browse the repository at this point in the history
Fix not-rendered math by conflict with Markdown All in One extension
  • Loading branch information
yhatt authored Mar 2, 2019
2 parents 5e34a8d + 1645019 commit 6dae1ef
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 432 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## [Unreleased]

### Fixed

- Fix not-rendered math by conflict with [Markdown All in One](https://github.com/yzhang-gh/vscode-markdown) extension ([#9](https://github.com/marp-team/marp-vscode/issues/9), [#11](https://github.com/marp-team/marp-vscode/pull/11))

### Changed

- Upgrade dependent packages to the latest ([#11](https://github.com/marp-team/marp-vscode/pull/11))

## v0.0.4 - 2019-02-13

### Changed
Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,33 @@
"watch": "rollup -w -c ./rollup.config.js"
},
"devDependencies": {
"@types/jest": "^24.0.3",
"@neilsustc/markdown-it-katex": "^0.3.0",
"@types/jest": "^24.0.9",
"@types/markdown-it": "^0.0.7",
"codecov": "^3.2.0",
"jest": "^24.1.0",
"jest-junit": "^6.2.1",
"jest-junit": "^6.3.0",
"markdown-it": "^8.4.2",
"markdown-it-emoji": "^1.4.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.16.4",
"rimraf": "^2.6.3",
"rollup": "^1.1.2",
"rollup-plugin-commonjs": "^9.2.0",
"rollup": "^1.4.0",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-typescript": "^1.0.0",
"stylelint": "^9.10.1",
"stylelint-config-prettier": "^4.0.0",
"stylelint-config-prettier": "^5.0.0",
"stylelint-config-standard": "^18.2.0",
"ts-jest": "^23.10.5",
"tslint": "^5.12.1",
"ts-jest": "^24.0.0",
"tslint": "^5.13.1",
"tslint-config-airbnb": "^5.11.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.3.3",
"vsce": "^1.57.0",
"vscode": "^1.1.29"
"typescript": "^3.3.3333",
"vsce": "^1.57.1",
"vscode": "^1.1.30"
},
"dependencies": {
"@marp-team/marp-core": "^0.6.1",
Expand Down
22 changes: 22 additions & 0 deletions src/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @jest-environment node */
import markdownItKatex from '@neilsustc/markdown-it-katex'
import { Marp } from '@marp-team/marp-core'
import markdownIt from 'markdown-it'
import markdownItEmoji from 'markdown-it-emoji'
Expand Down Expand Up @@ -45,6 +46,27 @@ describe('#extendMarkdownIt', () => {
})
})

describe('Math rendering', () => {
// @neilsustc/markdown-it-katex is used by Markdown All in One.
// https://github.com/yzhang-gh/vscode-markdown
const mdMath = extendMarkdownIt(new markdownIt().use(markdownItKatex))
const markdown = '$y=ax^2$\n\n$$ y=ax^2 $$'

it('renders math via Marp with marp front-matter', () => {
const html = mdMath.render(marpMd(markdown))

expect(html).toContain('<span class="katex">')
expect(html).toContain('data-marp-fitting-math')
})

it('renders math via existed plugin without marp front-matter', () => {
const html = mdMath.render(markdown)

expect(html).toContain('<span class="katex">')
expect(html).not.toContain('data-marp-fitting-math')
})
})

describe('Code highlight', () => {
const markdown = '```javascript\nconst test = 1\n```'

Expand Down
9 changes: 9 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ export function extendMarkdownIt(md: any) {

instance[marpVscodeEnabled] = enabled
state.marpit(enabled)

// Avoid collision to the other math plugins (markdown-it-katex)
if (enabled) {
md.block.ruler.disable('math_block', true)
md.inline.ruler.disable('math_inline', true)
} else {
md.block.ruler.enable('math_block', true)
md.inline.ruler.enable('math_inline', true)
}
})
})
.use(instance => {
Expand Down
Loading

0 comments on commit 6dae1ef

Please sign in to comment.