Skip to content

Commit

Permalink
fix markup space in first position 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
madneal committed Oct 22, 2017
1 parent 5b8f90e commit 54d36cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Export to Markdown",
"short_name": "ExportToMarkdown",
"description": "This is utilized to export the story in Medium to a markdown format file.",
"version": "0.1.2",
"version": "0.1.3",
"icons": {
"16": "icons/medium-16.png",
"48": "icons/medium-48.png",
Expand Down
33 changes: 26 additions & 7 deletions scripts/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ function parseJsonToMarkdown(jsonStr) {

const paragraphs = story.paragraphs
let lastPtype = ''
let sequence = 0;
let sequence = 0
for (let i = 0; i < paragraphs.length; i++) {
if (sections[i]) {
story.markdown.push(sections[i])
}
const p = paragraphs[i];
if (p.type === 10) {
sequence++;
sequence++
} else {
sequence = 0
}
Expand Down Expand Up @@ -131,6 +131,7 @@ function processParagraph(p, sequence) {
tokens.push(markups_array[j])
}
}
tokens = processMarkupSpace(tokens)
tokens.push(text.substring(j - 1))
p.text = tokens.join('')
}
Expand Down Expand Up @@ -186,6 +187,24 @@ function processParagraph(p, sequence) {
return p.text
}

// for the first position is space
function processMarkupSpace(tokens) {
let times = 0 // markup times
for (let i = 0; i < tokens.length; i++) {
const ele = tokens[i]
if (ele === '**' || ele === '*' || ele === '[' || ele === ']') {
times = times + 1;
if (times % 2 === 1 && tokens[i + 1] && tokens[i + 1][0] === ' ') {
console.log(tokens[i + 1]);
tokens[i + 1] = tokens[i + 1].substring(1);
tokens[i - 1] = tokens[i - 1] + ' '
i = i + 1;
}
}
}
return tokens;
}

function addMarkup(markups_array, open, close, start, end) {
if (markups_array[start]) {
markups_array[start] += open
Expand Down Expand Up @@ -217,11 +236,11 @@ function createMarkupsArray(markups) {
case 3: // anchor tag
addMarkup(markups_array, '[', '](' + m.href + ')', m.start, m.end)
break
case 10: // code tag
if (m.end - m.start < 30) {
addMarkup(markups_array, '`', '`', m.start, m.end)
}
break
// case 10: // code tag

This comment has been minimized.

Copy link
@sunui

sunui Mar 4, 2019

Contributor

Hello,Did you forget to make this note off? Or is there another reason for this?

// if (m.end - m.start < 30) {
// addMarkup(markups_array, '`', '`', m.start, m.end)
// }
// break
default:
console.log('Unknown markup type' + m.type, m)
break
Expand Down

0 comments on commit 54d36cd

Please sign in to comment.