-
Notifications
You must be signed in to change notification settings - Fork 3
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
support non-destructive editing of content w/ legacy shortcodes #1013
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1013 +/- ##
==========================================
+ Coverage 90.56% 90.67% +0.11%
==========================================
Files 196 197 +1
Lines 7547 7627 +80
Branches 1318 1329 +11
==========================================
+ Hits 6835 6916 +81
Misses 627 627
+ Partials 85 84 -1
Continue to review full report at Codecov.
|
54ae91c
to
1767922
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 The looks good to me and is working well in local trials.
One request: I think we should add baseurl to the legacy list. No baseurls have been converted yet (hopefully will today) but even after that conversion some will remain for a while.
@@ -64,3 +64,25 @@ export const TABLE_ALLOWED_ATTRS: string[] = ["colspan", "rowspan"] | |||
* with a double quote and captures anything in between the quotes. | |||
*/ | |||
export const ATTRIBUTE_REGEX = /(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|\s*\/?[>"']))+.)["']?/g | |||
|
|||
export const LEGACY_SHORTCODES = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested Change: I think we should add baseurl
to the list. Hopefully we'll remove it soon there's still some lingering baseurl issues #1015
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok cool, I was too optimistic 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also am I right in thinking that there's no harm in having it in the list even after the issue has been addressed via your PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also am I right in thinking that there's no harm in having it in the list even after the issue has been address via your PR?
yes, i agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not there then the rule won't apply right? There shouldn't be any harm to simply including it in this list, as even if we have a need for it in the future for some reason it would be manually inserted by us and won't be touched by editors.
} | ||
|
||
export default class LegacyShortcodes extends Plugin { | ||
static get requires(): Plugin[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: I'm not suggesting we should necessarily worry about this now... just writing it down
I think there's something weird here... I think the Plugin[]
type annotation is referring to globalThis.Plugin
. https://developer.mozilla.org/en-US/docs/Web/API/Plugin , not to CKEditor plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oooo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's why it's throwing errors...I'll take a minute to see if I can fix that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird...so I changed import Plugin from ...
to import { default as CKEditorPlugin } from ...
and then I get an error about being unable to use that type in a static method...I think I might just leave this off for now in the interest of time
but it would be good to fix!
|
||
const tag = `<span ${DATA_ISCLOSING}="${isClosing}" ${ | ||
shortcodeArgs ? | ||
`${DATA_ARGUMENTS}="${escape(shortcodeArgs)}"` : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question/Suggestion: I was unfamiliar with escape
and VSCode highlighted it, so I looked it up on MDN. MDN says not to use it, but doesn't really explain why. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape Would encodeURIComponent
work instead?
Edit: Google makes me think that the reason it's recommended against is that it occasionally produces invalid URLs. Since we're not using it for that, probably not a concern? But if something not deprecated works, that seems better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use encoreURIComponent, I'll swap that in and make sure the tests pass real quick. The reason to do it is just that if it's not escaped then the text w/in the arguments to a shortcode can cause issues correctly finding the boundaries of the HTML tags later on and things get all messed up. When I was hacking on it I actually used btoa
and atob
to be 100% sure I wasn't going to get any characters I didn't expect in the arguments string, haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, it seems that escape
doesn't support "higher order unicode characters," and the only suggestion I see as a replacement as well is encode/decodeUriComponent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, I already made the change since all the tests pass with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm approving this, as it tested out well for me locally. I think the things @ChristopherChudzicki noted should be checked out still though. The escape
thing isn't critical as it's not going away anytime soon, but might be better to use encodeUriComponent
.
|
||
const tag = `<span ${DATA_ISCLOSING}="${isClosing}" ${ | ||
shortcodeArgs ? | ||
`${DATA_ARGUMENTS}="${escape(shortcodeArgs)}"` : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, it seems that escape
doesn't support "higher order unicode characters," and the only suggestion I see as a replacement as well is encode/decodeUriComponent
@@ -64,3 +64,25 @@ export const TABLE_ALLOWED_ATTRS: string[] = ["colspan", "rowspan"] | |||
* with a double quote and captures anything in between the quotes. | |||
*/ | |||
export const ATTRIBUTE_REGEX = /(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|\s*\/?[>"']))+.)["']?/g | |||
|
|||
export const LEGACY_SHORTCODES = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not there then the rule won't apply right? There shouldn't be any harm to simply including it in this list, as even if we have a need for it in the future for some reason it would be manually inserted by us and won't be touched by editors.
This implements support for nondestructively editing markdown files which have 'legacy' shortcodes in them (these are shortcodes inserted into converted content by ocw-to-hugo to support a series of things which aren't supported in plain markdown). A manifest of these shortcodes is declared in `static/js/lib/ckeditor/plugins/constants.ts`, and support for them is implemented in a new CKEditor plugin called `LegacyShortcodes`. This will enable non-destructive editing of markdown content which contains these shortcodes, fixing an issue we were seeing where raw shortcodes that were unknown to CKEditor were being escaped and the showing up in the rendered HTML. This fixes this by adding a node type to CKEditor for each one, and adding basical logic for preserving any arguments to the shortcodes. Note that this change does NOT in any way way enable _editing these shortcodes themselves_. Instead, they are made obvious in the editor with a basic display, but it is up to the content editors to not delete them or anything like that (and right now they could only be added to a file manually in the Django admin or shell). pr #1013
c42895e
to
07290e8
Compare
Pre-Flight checklist
What are the relevant tickets? #1025
(Required)
What's this PR do?
This implements support for nondestructively editing markdown files which have 'legacy' shortcodes in them (these are shortcodes inserted into converted content by ocw-to-hugo to support a series of things which aren't supported in plain markdown).
How should this be manually tested?
You'll need to get some shortcode-filled markdown into one of your pages and then test out that it displays like in the little video below.
etc
This is a little snippet that you might want to try:
it's an example of a quiz, which uses a whole bunch of shortcodes, opening and closing ones, with arguments, etc.
Screenshots (if appropriate)
Screen.Recording.2022-02-16.at.6.20.36.PM.mov