Skip to content

Commit

Permalink
feature: 支持strikethrough语法,修改插件导出方式
Browse files Browse the repository at this point in the history
  • Loading branch information
siaikin committed Oct 20, 2019
1 parent c7b7005 commit c0d5e06
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 14 deletions.
3 changes: 2 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mdReserve = new MdReverse();

mdReserve.use(new MdReverse.TablePlugin());
mdReserve.use(MdReverse.plugin['table']);
mdReserve.use(MdReverse.plugin['strickthrough']);
const htmlArea = document.getElementById('html-area');
const mdArea = document.getElementById('markdown-area');

Expand Down
5 changes: 1 addition & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
const url = `${location.protocol}//${location.host}${location.pathname}`;
let replaceUrl;
if (/(\/index\.html\/?|\/)/g.test(url)) {
replaceUrl = url.replace(/(\/index\.html\/?|\/)$/, "/dist/index.html");
replaceUrl = url.replace(/(\/index\.html\/?|\/)$/, "/demo/index.html");
window.location.replace(replaceUrl);
} else {
document.writeln('ERROR');
document.writeln('<h1>老哥,url地址有问题,用下面那个试一下</h1>');
document.writeln('<a href="https://siaikin.github.io/mdReverse/dist/index.html">下面这个</a>');
document.writeln('<a href="https://siaikin.github.io/mdReverse/index.html">不行还有这个</a>');
}
</script>
</body>
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {CONSOLE_TYPE} from './lib/config';
import {MdReverse, TablePlugin} from "./lib/mdReverse";
import {MdReverse, TablePlugin, StrikethroughPlugin} from "./lib/mdReverse";

MdReverse.TablePlugin = TablePlugin;
MdReverse.plugin = {
table: TablePlugin,
strickthrough: StrikethroughPlugin
};

const consolee = window.console;

Expand Down
6 changes: 4 additions & 2 deletions src/lib/mdReverse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {REGEXP, EL_TYPE, TOKEN_RULE, DEFAULT_RULE, addToken} from "./config";
import {TablePlugin} from "./plugins/table";
import {StrikethroughPlugin} from "./plugins/strikethrough";
import {Lexer} from "./lexer";
import {Parser} from "./parser";
import {VDOMTree} from "./vdomt";
Expand Down Expand Up @@ -36,10 +37,11 @@ function toMarkdown(htmlStr) {
}

function use(plugin) {
plugin.plugin(addToken, EL_TYPE, DEFAULT_RULE);
plugin(addToken, EL_TYPE, DEFAULT_RULE);
return this;
}
export {
MdReverse,
TablePlugin
TablePlugin,
StrikethroughPlugin
}
25 changes: 25 additions & 0 deletions src/lib/plugins/strikethrough.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {Tools} from "../tools/tools";

/**
* [Strikethrough扩展语法]{ https://www.markdownguide.org/extended-syntax/#strikethrough}
* @param addToken
* @param EL_TYPE
* @constructor
*/
function StrikethroughPlugin(addToken, EL_TYPE) {
addToken('del', true, {
filterRule: {
children: [EL_TYPE['all_element']]
},
convertRule: function (node) {
return ' ~~';
},
endRule: function (node) {
return `~~ `;
}
})
}

export {
StrikethroughPlugin
}
8 changes: 3 additions & 5 deletions src/lib/plugins/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import {Tools} from "../tools/tools";
/**
* [Table扩展语法]{ https://www.markdownguide.org/extended-syntax/#tables}
* @param addToken
* @param EL_TYPE
* @constructor
*/
function TablePlugin() {
}

TablePlugin.prototype.plugin = function (addToken, EL_TYPE) {
function TablePlugin(addToken, EL_TYPE) {
addToken('td', true, {
filterRule: {
children: [EL_TYPE['all_element']]
Expand Down Expand Up @@ -96,7 +94,7 @@ TablePlugin.prototype.plugin = function (addToken, EL_TYPE) {
return '';
}
});
};
}

export {
TablePlugin
Expand Down

0 comments on commit c0d5e06

Please sign in to comment.