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

Markdown Preprocessor for Lesson Plans #39310

Merged
merged 9 commits into from
Mar 8, 2021

Conversation

Hamms
Copy link
Contributor

@Hamms Hamms commented Mar 3, 2021

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

Caching

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:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@Hamms Hamms marked this pull request as ready for review March 4, 2021 00:48
@Hamms Hamms requested a review from a team March 4, 2021 00:48
Copy link
Member

@davidsbailey davidsbailey left a 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.
Copy link
Member

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?

Copy link
Contributor Author

@Hamms Hamms Mar 4, 2021

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)}"
Copy link
Member

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"

Copy link
Member

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!

Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

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

nit: "modify"

Comment on lines 218 to 222
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
Copy link
Member

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>
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please!

@Hamms Hamms merged commit d2e68f5 into staging Mar 8, 2021
@Hamms Hamms deleted the lesson-plan-markdown-preprocessor branch March 8, 2021 17:20
Hamms added a commit that referenced this pull request Mar 11, 2021
…taxes

Since those values are necessary to _actually_ uniquely identify resources and vocabularies.

Depends on #39461; follow-up to #39447 and #39310
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants