Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bold texts loosing formatting after converting to markdown and back to wysiwyg #15

Merged
merged 5 commits into from
Jul 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/woofmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,21 @@ function woofmark (textarea, options) {
if (currentMode === 'html') {
textarea.value = parse('parseHTML', textarea.value).trim();
} else {
textarea.value = parse('parseHTML', editable).trim();
var regexp = /\*\*[A-Z][^*]+ \*\*/gi;
Shulammite-Aso marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a better name for this regex? Instead of using regex and regex2 as variable name, can we have a separate utils file where each regex is defined (can be done in a separate PR)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was intending to comment the code, and will think of something more suitable to rename the variable with like your're suggesting. About a utils file, do you mean putting this code in a function and importing from a utils file?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes only this regex line but it can be done later. No worries 👍

textarea.value = parse('parseHTML', editable).trim();
if (textarea.value.match(regexp)) {
var reg = textarea.value.match(regexp);

for (let i = 0; i <= reg.length - 1; i++) {
var regexp2 = /\*\*[A-Z][^*]+ \*\*/i;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are re declarating this regex on each for iteration.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regexp2 should go outside the iteration sorry. will fix this.

if (textarea.value.match(regexp2)) {
reg[i] = reg[i].replace(' **', '** ')
textarea.value = textarea.value.replace(regexp2, reg[i])
//console.log(textarea.value);
}
}
}

}
} else if (nextMode === 'html') {
if (currentMode === 'markdown') {
Expand Down