Skip to content

Commit

Permalink
Fixed sync render failed for showdown wavedrom extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhuix committed Nov 29, 2019
1 parent 3f18ea6 commit e5e4549
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
node_modules
/dist
/lib
/fonts
/testdemo
*-lock.json

# local env files
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
node_modules
/docs
/testdemo
*-lock.json
.babelrc
.editorconfig
Expand Down
2 changes: 1 addition & 1 deletion docs/dist/showdowns.br.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.

4 changes: 2 additions & 2 deletions docs/showdowns-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# [Showdowns Features](https://jhuix.github.io/showdowns)

[TOC]

[Showdowns](https://github.com/jhuix/showdowns) is a lib that make markdown to html with some extensions of showdown.js.
Click the link to preview the [showdowns features](https://jhuix.github.io/showdowns).

Showdowns Markdown Syntax, refer to the document -- [Showdown's Markdown Syntax](https://github.com/showdownjs/showdown/wiki/Showdown's-Markdown-syntax).

## Table

| Return Code | Style | Value | DESC |
Expand Down
4 changes: 2 additions & 2 deletions public/showdowns-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# [Showdowns Features](https://jhuix.github.io/showdowns)

[TOC]

[Showdowns](https://github.com/jhuix/showdowns) is a lib that make markdown to html with some extensions of showdown.js.
Click the link to preview the [showdowns features](https://jhuix.github.io/showdowns).

Showdowns Markdown Syntax, refer to the document -- [Showdown's Markdown Syntax](https://github.com/showdownjs/showdown/wiki/Showdown's-Markdown-syntax).

## Table

| Return Code | Style | Value | DESC |
Expand Down
16 changes: 15 additions & 1 deletion src/extensions/showdown-wavedrom.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if (typeof wavedrom === 'undefined') {
var wavedrom = WaveDrom;
}

let wdCount = 0;
let indexWD = 0;

function hasWavedrom() {
return !!wavedrom;
}
Expand All @@ -30,6 +30,12 @@ function renderWavedrom(element, sync) {
const index = indexWD;
const id = 'WaveDrom_Display_' + index;
++indexWD;
// When index of wavwdrom is 0, there will be some special logic in the WaveDrom lib.
// So the index needs to be cleared after all WavwDrom element are rendered.
--wdCount;
if (!wdCount) {
indexWD = 0;
}
if (!sync && typeof window !== 'undefined' && window.dispatchEvent) {
element.id = id;
Promise.resolve(id).then(elementid => {
Expand All @@ -53,6 +59,13 @@ function renderWavedrom(element, sync) {
el => {
const obj = window.eval(`(${code})`);
wavedrom.RenderWaveForm(index, obj, 'WaveDrom_Display_');
// Replace the created cache element with the original element with the same id.
const wdel = document.getElementById('WaveDrom_Display_' + index);
if (el != wdel) {
while (wdel.childNodes.length) {
el.appendChild(wdel.removeChild(wdel.childNodes[0]));
}
}
}
);
}
Expand All @@ -64,6 +77,7 @@ function renderWavedromElements(elements, skin) {
return false;
}

wdCount = elements.length;
const sync = hasWavedrom();
if (typeof window !== 'undefined') {
if (!sync) {
Expand Down

0 comments on commit e5e4549

Please sign in to comment.