-
Notifications
You must be signed in to change notification settings - Fork 130
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
New line added with bold formatting #457
Comments
@jywarren @emilyashley @cesswairimu please verify the same. |
Hey @Shreyaa-s yeah I see that is happening...it doesn't happen on the PL website implementation of the editor though its worth checking whats up...would be interested in working on this? thanks |
hey @cesswairimu sure! I would love to give this a try. Thanks |
@Shreyaa-s Any updates, are you still working on this? I guess this issue is with the text present in a bulleted list or in the row and column format. Can you look further and confirm. |
@govindgoel I checked but the bug doesn't follow a fixed pattern. Sometimes it adds a new line to plain text as well and sometimes it doesn't. I have trouble pinpointing the exact snippet of code that breaks. I will keep you posted if I come across anything. |
@keshav234156 @NitinBhasneria @Shulammite-Aso if any of you has worked with woofmark before, can you help me figure out how this function works? Thanks. var rleading = /^(\**)/;
var rtrailing = /(\**$)/;
var rtrailingspace = /(\s?)$/;
var strings = require('../strings');
function boldOrItalic (chunks, type) {
var rnewlines = /\n{2,}/g;
var starCount = type === 'bold' ? 2 : 1;
chunks.trim();
chunks.selection = chunks.selection.replace(rnewlines, '\n');
var markup;
var leadStars = rtrailing.exec(chunks.before)[0];
var trailStars = rleading.exec(chunks.after)[0];
var stars = '\\*{' + starCount + '}';
var fence = Math.min(leadStars.length, trailStars.length);
if (fence >= starCount && (fence !== 2 || starCount !== 1)) {
chunks.before = chunks.before.replace(new RegExp(stars + '$', ''), '');
chunks.after = chunks.after.replace(new RegExp('^' + stars, ''), '');
} else if (!chunks.selection && trailStars) {
chunks.after = chunks.after.replace(rleading, '');
chunks.before = chunks.before.replace(rtrailingspace, '') + trailStars + RegExp.$1;
} else {
if (!chunks.selection && !trailStars) {
chunks.selection = strings.placeholders[type];
}
markup = starCount === 1 ? '*' : '**';
chunks.before = chunks.before + markup;
chunks.after = markup + chunks.after;
} |
@Shreyaa-s This function is for Italic and Bold formatting in markdown mode.
This checks number of leading and trailing You can get to know more about the function by adding a console.log(name_of_variable) statement and trying different test cases. |
The problem with bold tags only occurs in rich text mode, or when we switch modes. From what I've observed the problem goes like this. Sample Text: This is because the bold formatting functions like this: While selecting text: After the bold operation: As you can see an additional |
The function |
@jywarren I had a query. Since you've worked with this piece of code before, is there any case where closing any open tag before formatting would be absolutely necessary? Because from what I've observed simply not calling the |
Hi, what tremendous investigating is going on here! Really great and super good collaboration too. Congrats all! This is especially tough code to dig through, too. I can't think of a case, but a few thoughts:
|
Wow, this is really impressive detective work! I'm amazed! |
Could you point me to where the woofmark tests are defined? I went through the code and description of woofmark but couldn't pinpoint them. I'm thinking of cases where |
I think that woofmark is not protected by tests. |
Hmm, apologies, i believe what happened is that Each of these have tests. And |
@Shreyaa-s Are you able to figure out what pushover() and pushoverOthersTag() are doing? I am still not able to get it. |
Hi @keshav234156 , here's a rough idea: var rclosed = new RegExp('<\/' + tag.replace(/</g, '</') + '>', 'i');
var ropened = new RegExp('<' + tag + '( [^>]*)?>', 'i'); Here we check if a a tag is opened but not closed in the selected part, then it adds a closing tag after the selected part. An example would be, if the selected part is
The end result would be :
Code: if (open && !rclosed.test(chunks.selection.substr(i))) {
chunks.selection += '</' + tag + '>';
chunks.after = chunks.after.replace(/^(<\/[^>]+>)/, '$1<' + tag + attrs + '>');
} Similarly this looks if a tag is closed but not opened in the selected text. For example if (closing && !ropened.test(chunks.selection.substr(0, i))) {
chunks.selection = '<' + tag + attrs + '>' + chunks.selection;
chunks.before = chunks.before.replace(/(<[^>]+(?: [^>]*)?>)$/, '</' + tag + '>$1');
} |
The more I work on this, the more I feel that I'm not looking in the right direction. People tend to bolden a word or a line, not a complete list. And even if we want to apply it to a list the ideal way would be:
And how it implements right now is:
This breaks if we convert it to md and back, the reason why I was learning how data is parsed. |
This is really good investigation, thank you @Shreyaa-s !! I tend to agree with you that the existing model for nesting boldness and lists is not right. It could be worth looking if HTML even strictly allows for lists inside of What we could do is implement a secondary model for it, nested differently, and include a switch in the options. The advantage would be that this wouldn't break any existing tests or downstream usages in the old model, and would allow us to introduce our "better" model with a test of our own which would side-step the debate about which model is better :-) What do you think? |
Hey @jywarren ! I looked into it and HTML does allow lists inside Not getting the desired output in the above-mentioned test case is due to how we parse the code between different modes. On that note, this is just one test case, there's a high possibility that somewhere else too the code breaks because of a similar reason. We could club all such bugs together and then think of a solution. What do you all think? |
This sounds perfect, @Shreyaa-s. And, any PR and/or tests we use could help to explain/demo the various cases and why it's a complex situation. |
Please describe the problem (or idea)
When a snippet of plain text is selected and bold formatting is applied, a new line is added to the bottom of the plain text.
Representation of the same:

Thanks
The text was updated successfully, but these errors were encountered: