Skip to content

Commit

Permalink
Fixed method removeAsyncExtension and removeExtension of showdowns co…
Browse files Browse the repository at this point in the history
…uld not remove related extensions.
  • Loading branch information
jhuix committed Oct 13, 2020
1 parent d62d698 commit bf3a49c
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docs/dist/showdowns.min.css

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

4 changes: 2 additions & 2 deletions docs/dist/showdowns.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/dist/showdowns.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@rollup/plugin-replace": "^2.3.3",
"autoprefixer": "^9.8.6",
"cssnano": "^4.1.10",
"eslint": "^7.8.1",
"eslint": "^7.11.0",
"less": "^3.12.2",
"postcss-banner": "^3.0.2",
"postcss-nested": "^4.2.3",
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/asciimath2tex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Based on ASCIIMathTeXImg.js but now part of showdowns.js
Based on ASCIIMathTeXImg.js but now part of https://github.com/jhuix/showdowns.git
Based on ASCIIMathML, Version 1.4.7 Aug 30, 2005, (c) Peter Jipsen http://www.chapman.edu/~jipsen
Modified with TeX conversion for IMG rendering Sept 6, 2006 (c) David Lippman http://www.pierce.ctc.edu/dlippman
Expand Down
1 change: 1 addition & 0 deletions src/extensions/showdown-flowchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ function showdownFlowchart(userOptions) {
return [
{
type: 'output',
config: options,
filter: function(obj) {
const wrapper = obj.wrapper;
if (!wrapper) {
Expand Down
1 change: 1 addition & 0 deletions src/extensions/showdown-katex.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const showdownKatex = userConfig => {
return [
{
type: 'output',
config: config,
filter: function(obj) {
const wrapper = obj.wrapper;
if (!wrapper) {
Expand Down
4 changes: 4 additions & 0 deletions src/extensions/showdown-mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ function dyncLoadScript(config) {
mermaid = cdnjs.interopDefault(window[name]);
mermaid.initialize(config);
});
return sync
}
}

mermaid.initialize(config);
return sync;
}

Expand Down Expand Up @@ -138,6 +141,7 @@ function showdownMermaid(userConfig) {
return [
{
type: 'output',
config: config,
filter: function(obj) {
const wrapper = obj.wrapper;
if (!wrapper) {
Expand Down
5 changes: 4 additions & 1 deletion src/extensions/showdown-plantuml.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import plantumlcodec from '../utils/plantuml-codec.js';
const defaultUmlWebsite = 'www.plantuml.com/plantuml';
const defaultImageFormat = 'img';

let umlElementCount = 0;
function renderPlantumlElement(element, config) {
return new Promise(resolve => {
const langattr = element.dataset.lang;
Expand Down Expand Up @@ -41,7 +42,7 @@ function renderPlantumlElement(element, config) {
if (imageFormat === 'svg') {
const id = 'plantuml-' + Date.now() + '-' + Math.floor(Math.random() * 10000);
if (typeof config.svgRender === 'function' && config.svgRender) {
config.svgRender(id, name, code).then(svgData => {
config.svgRender(id, name, code, umlElementCount).then(svgData => {
element.parentNode.outerHTML = `<div id="${id}" class="${name}">${svgData}</div>`;
resolve(true);
});
Expand Down Expand Up @@ -77,6 +78,7 @@ function renderPlantumlElement(element, config) {

// <div class="plantuml"></div>
function renderPlantumlElements(elements, config) {
umlElementCount = elements.length;
return new Promise(resolve => {
const promiseArray = [];
elements.forEach(element => {
Expand All @@ -102,6 +104,7 @@ function showdownPlantuml(userConfig) {
return [
{
type: 'output',
config: config,
filter: function(obj) {
const wrapper = obj.wrapper;
if (!wrapper) {
Expand Down
1 change: 1 addition & 0 deletions src/extensions/showdown-vega.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function showdownVega(userOptions) {
return [
{
type: 'output',
config: options,
filter: function(obj) {
const wrapper = obj.wrapper;
if (!wrapper) {
Expand Down
7 changes: 4 additions & 3 deletions src/extensions/showdown-wavedrom.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,13 @@ const getConfig = (config = {}) => ({
...config
});

function showdownWavedrom(config) {
const skin = getConfig(config).skin;
function showdownWavedrom(skinConfig) {
const config = getConfig(skinConfig)

return [
{
type: 'output',
config: config,
filter: function(obj) {
const wrapper = obj.wrapper;
if (!wrapper) {
Expand All @@ -174,7 +175,7 @@ function showdownWavedrom(config) {
}

console.log(`${new Date().Format('yyyy-MM-dd hh:mm:ss.S')} Begin render wavedrom elements.`);
return renderWavedromElements(elements, skin).then(() => {
return renderWavedromElements(elements, config.skin).then(() => {
console.log(`${new Date().Format('yyyy-MM-dd hh:mm:ss.S')} End render wavedrom elements.`);
return obj;
});
Expand Down
8 changes: 0 additions & 8 deletions src/parser/showdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ showdown.asyncExtension = function(name, ext) {
}
};

/**
* Get an async extension
* @param {string} name
*/
showdown.getAsyncExtension = function(name) {
'use strict';
return _asyncExtensions[name];
};
/**
* Remove an async extension
* @param {string} name
Expand Down
13 changes: 6 additions & 7 deletions src/showdowns.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const showdowns = {
if (!ext) return;
this.converter.removeExtension(ext);
}
name = showdown.helper.stdExtName(name);
showdown.removeExtension(name);
},
addAsyncExtension: function(name, extension) {
Expand Down Expand Up @@ -195,6 +196,7 @@ const showdowns = {
if (!ext) return;
this.converter.removeAsyncExtension(ext);
}
name = showdown.helper.stdExtName(name);
showdown.removeAsyncExtension(name);
},
setCDN: function(cdnname, defScheme, distScheme) {
Expand Down Expand Up @@ -283,14 +285,11 @@ const showdowns = {
name = name || null;
// If it's a string, the extension was previously loaded
if (showdown.helper.isString(ext)) {
ext = showdown.helper.stdExtName(ext);
name = ext;

if (!showdown.helper.isUndefined(showdown.getAsyncExtension(ext))) {
ext = showdown.getAsyncExtension(ext);
} else {
name = showdown.helper.stdExtName(ext);
ext = showdown.asyncExtension(name);
if (showdown.helper.isUndefined(ext)) {
throw Error(
'Extension "' + ext + '" could not be loaded. It was either not found or is not a valid aync extension.'
'Extension "' + name + '" could not be loaded. It was either not found or is not a valid aync extension.'
);
}
}
Expand Down

0 comments on commit bf3a49c

Please sign in to comment.