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

Ampersand in code blocks is recursively changed to & each save #917

Closed
myii opened this issue Mar 17, 2020 · 16 comments
Closed

Ampersand in code blocks is recursively changed to & each save #917

myii opened this issue Mar 17, 2020 · 16 comments

Comments

@myii
Copy link

myii commented Mar 17, 2020

Version: 0.40.5

Steps to reproduce:

  • In a text note, add a code block with a single ampersand, i.e.
&
  • Navigate to another note and then come back to this note and now it will be displayed as:
&
  • Add any other text to the note so that another save takes place; navigate away and then back to the note and now it will be displayed as:
&
  • This continues recursively each time the note is saved until you can even end up with:
&
  • In my actual use-case with a bash snippet containing &&, I've now got:
... && ...
@zadam
Copy link
Owner

zadam commented Mar 17, 2020

Hello, yes, this is a known issue in CKEditor - see ckeditor/ckeditor5#5901

It is quite unfortunate that this has not been fixed yet.

@myii
Copy link
Author

myii commented Mar 17, 2020

Thanks for the prompt response, @zadam. Ouch, that's a nasty bug upstream. Have you come across any workarounds for this?

@zadam
Copy link
Owner

zadam commented Mar 17, 2020

I don't know any workaround unfortunately.

@dtomlinson91
Copy link

dtomlinson91 commented Mar 30, 2020

The workaround I'm using is create a js frontend note say replaceamp

var find_1 = '&&'

var repl = '&';

var re_1 = new RegExp(find_1, 'g');

document.getElementsByClassName('language-text-x-sh')[0].innerText = document.getElementsByClassName('language-text-x-sh')[0].innerText.replace(re_1, repl)

then use @runOnNoteView=replaceamp as a tag on the note you want.

You can change the css class language-text-x-sh to whatever code it is or loop through all possibilities.

It's a bit inelegant and a not very nice to have to tag loads of notes, but it's a workaround until this is fixed.

@myii
Copy link
Author

myii commented Apr 1, 2020

@dtomlinson91 That looks like a useful snippet. Surely we could use a loop to work through all of the relevant elements on the page. If I get a chance, I'll try at my end.

BTW, there's a slight difference between my findings (-) and yours (+):

-&
+&&

@KodaCHC
Copy link

KodaCHC commented Apr 11, 2020

Thank you.

You can change the css class language-text-x-sh to whatever code it is or loop through all possibilities.

Can you help me with this step?
I have set up a new note with name "replaceamp". The Type is JS frontend

Then I have set up the attribute on my note but I have allways & and not &.

I have this issue not only with &. The same with  . I hope on a fix :)

@dtomlinson91
Copy link

Thank you.

You can change the css class language-text-x-sh to whatever code it is or loop through all possibilities.

Can you help me with this step?
I have set up a new note with name "replaceamp". The Type is JS frontend

Then I have set up the attribute on my note but I have allways & and not &.

I have this issue not only with &. The same with . I hope on a fix :)

Can you post the contents of the js frontend note you're using. Also posting some text from the note you want to run it on showing what you're trying to replace.

@KodaCHC
Copy link

KodaCHC commented Apr 14, 2020

I have copy your replaceamp content.
My issue are around in 50 or 60 notes with different ampersands for Codesnippeds or linux commands.

The most Ampersands are from HTML Chars and commands. Also &, &&, &nbsb; and other.. And allways when this will changed to & i will replace it.

Very rarely I have a &, but I think I have to ignore this for now

I hope this will be fixed soon

@myii
Copy link
Author

myii commented May 6, 2020

There's been quite a bit of activity on the upstream issue so hopefully there's a solution around the corner:

@popey456963 popey456963 changed the title [Bug] Ampersand in code blocks is recursively changed to & each save Ampersand in code blocks is recursively changed to & each save May 7, 2020
@myii
Copy link
Author

myii commented May 21, 2020

Good news, the upstream bug has been fixed (apparently) -- will this reach the next released version of Trilium, @zadam?

@zadam
Copy link
Owner

zadam commented May 21, 2020

First CKEditor needs to make a release (I think they have one planned within a week).

@myii
Copy link
Author

myii commented May 21, 2020

OK, at least we know it's in the pipeline. Thanks for the ongoing development!

@zadam
Copy link
Owner

zadam commented May 31, 2020

Fixed in 0.42.4.

@zadam zadam closed this as completed May 31, 2020
@myii
Copy link
Author

myii commented May 31, 2020

Lovely, thanks @zadam! Quick question if you get a chance: with no find & replace, is it OK to run queries against the database itself or can that mess things up, like note revisions?

@zadam
Copy link
Owner

zadam commented May 31, 2020

changing note_contents.content should be OK via query (only notes with isProtected=0)

@myii
Copy link
Author

myii commented May 31, 2020

changing note_contents.content should be OK via query (only notes with isProtected=0)

Thanks, that's useful to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants