-
Notifications
You must be signed in to change notification settings - Fork 481
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
Markdown Preprocessor for Lesson Plans #39310
Conversation
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.
This looks great, @Hamms ! Nice unit tests!
@@ -101,7 +102,7 @@ def generate_key_from_name | |||
# something simple like gsub (which can only do positive matches) we have | |||
# to do something manual. |
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 know this may be out of scope for this PR, but I think I am missing something about this comment here -- wouldn't something like the following work?
STACK_NAME_INVALID_REGEX = /[^[[:alnum:]-]]/ stack_name.gsub!(STACK_NAME_INVALID_REGEX, '-')
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'd like to have a single regex that's the source of truth. I don't want to have to do something like
VALID_KEY_CHAR_RE = /[a-z0-9\-\_]/
INVALID_KEY_CHAR_RE = /[^a-z0-9\-\_]/
# for relevant documentation | ||
def self.process!(content, cache_options: nil) | ||
return content unless content.present? | ||
cache_key = "MarkdownPreprocessor/process/#{Digest::MD5.hexdigest(content)}" |
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 am curious, what is the motivation for hashing the cache key? It seems like it might(?) make things harder to debug, and I'm having trouble imagining inputs that would be much longer than an MD5 hexdigest:
[development] dashboard > Digest::MD5.hexdigest('[v computer-science]')
=> "ea78c2daad5e16fc4e4ef1a21fa98e61"
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.
oh, or is it the entire block of text (overview, activity section description, etc)? if so, makes sense to hash!
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.
yeah, it's the entire block
end | ||
end | ||
|
||
test 'regular method returns and does not modifiy' do |
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.
nit: "modify"
dashboard/test/models/lesson_test.rb
Outdated
test 'lesson edit summary does not preprocess markdown' do | ||
lesson = create :lesson, lesson_group: create(:lesson_group) | ||
Services::MarkdownPreprocessor.expects(:process).never | ||
lesson.summarize_for_lesson_edit | ||
end |
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.
better to expects(:process!)
here, to prevent calls to both .process
and .process!
?
@@ -56,6 +56,12 @@ class FindResourceDialog extends Component { | |||
))} | |||
</select> | |||
</label> | |||
<p> |
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.
Will the "real" link show in the preview on the right side of the edit page?
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.
Great question Dani! I don't think it will be practical to show this during live editing for April, so my thought would be to let the live preview just show the raw [r ...]
syntax. One idea for the future would be to show these live previews with resolved links after each time the page is saved -- though it seems like we'd have to stop resolving the links as soon as the editor started changing the markdown, unless we want to send ajax requests to resolve them again.
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've got a couple ideas of ways we could do various kinds of fanciness to get something like what you're talking about Dave to work, but I agree that they're all too much to try to get done for April.
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.
Sounds good! Should we track the follow up in Jira for Q2?
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.
Yes, please!
…y the other, so by testing against that we actually verify both
Adds the ability to render markdown syntax which requires database access.
Specifically, we add a "preprocess" step in the rendering process for certain markdown-enabled strings, which will replace certain serverside-only syntaxes with vanilla markdown equivalent. Currently used for Resource Links, will be extended to include Vocab Links in the near future, and could be further extended with other kinds of content in the distant future.
Links
Testing story
Added some pretty extensive unit tests. I'd be happy to add some ui tests as well if folks think they're necessary.
Follow-up work
TextareaWithImageUpload
component to instead beMarkdownEnabledTextarea
#39333Caching
This functionality is heavily cached by the input strings. I don't imagine we'll ever be in a situation where we want to update Resource data on production outside the context of a deploy with it associated cache expiration, but feel free to let me know if I'm missing something.
PR Checklist: