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

feat(v2): add ability default lang for code blocks #1910

Merged
merged 13 commits into from
Nov 5, 2019

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Oct 29, 2019

Motivation

It often happens that in Markdown code blocks do not (intentionally) specify the language, and then the default language was used. This is convenient if the examples language in docs is the same (why should it be indicated all the time?). Or, for example, when end-user forgot to specify that language.

Note: if you do not specify a language, then in HTML it will be represented as language-undefined.

In v1 there was such an feature, I propose to bring back it to v2.

Also in this PR, as an experiment, changed way to provide options for Prism - in a separate object (as it was in v1). This is a breaking change, yes, but in the end it is a flexible approach, because in the future there may be more options for highlighting code (=Prism).

- themeConfig.prismTheme
- themeConfig.prismDefaultLanguage
+ themeConfig.prism: {
+   theme: ...
+   defaultLanguage: ...
+   // and so on
+ }

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

  1. Set the following options in docusaurus.config.js:
// ...  
  themeConfig: {
  // ...
    prism: {
      defaultLanguage: 'js',
      theme: require(...),
    },
  1. In docs, omit the language in the code block:
```
console.log('JS is my default language!')
```
  1. Make sure that the given code block is highlighted as js:
console.log('JS is my default language!')

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 29, 2019
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Oct 29, 2019

Deploy preview for docusaurus-2 ready!

Built with commit c94f027

https://deploy-preview-1910--docusaurus-2.netlify.com

@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Oct 29, 2019

Deploy preview for docusaurus-preview ready!

Built with commit c94f027

https://deploy-preview-1910--docusaurus-preview.netlify.com

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

I'm ok with this. But I think we should alert people of the breaking changes by throwing an error in __DEV__ if prismTheme is being declared.

Also we need CHANGELOG changes and docs changes in https://v2.docusaurus.io/docs/markdown-features#syntax-highlighting.

@endiliey WDYT?

Copy link
Contributor

@endiliey endiliey left a comment

Choose a reason for hiding this comment

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

i thought this is still wip ?

@lex111
Copy link
Contributor Author

lex111 commented Nov 3, 2019

It was a proof of concept, to show you, I will soon complete this PR.

But I think we should alert people of the breaking changes by throwing an error in DEV if prismTheme is being declared.

Fine, although I would merely decide note in change log, given that this is an alpha version

@endiliey
Copy link
Contributor

endiliey commented Nov 3, 2019 via email

@lex111
Copy link
Contributor Author

lex111 commented Nov 4, 2019

Hmm, I have a problem, I don’t know how to document the new defaultLanguage field, because in the current version of docs v2 there is no section about Prism ;/

Copy link
Contributor

@endiliey endiliey left a comment

Choose a reason for hiding this comment

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

We can start documenting here. https://v2.docusaurus.io/docs/theme-classic

Under new CodeBlock section.

@lex111 lex111 changed the title feat(v2): add ability default lang for code blocks [WIP] feat(v2): add ability default lang for code blocks Nov 4, 2019
@lex111
Copy link
Contributor Author

lex111 commented Nov 4, 2019

Ready for review! ✔️

Copy link
Contributor

@endiliey endiliey left a comment

Choose a reason for hiding this comment

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

I'm gonna stop https://v2.docusaurus.io/ auto publishing on master push. We should only deploy the docs after new version is out

website/docs/theme-classic.md Outdated Show resolved Hide resolved
Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

LGTM. cc @endiliey for another approval

Copy link
Contributor

@endiliey endiliey left a comment

Choose a reason for hiding this comment

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

feel free to merge.

Squash and merge. please ✌️

@lex111 lex111 merged commit c507028 into facebook:master Nov 5, 2019
@lex111 lex111 deleted the prism-def-lang branch November 5, 2019 07:36
@lex111
Copy link
Contributor Author

lex111 commented Nov 5, 2019

So exciting, merged!

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

Successfully merging this pull request may close these issues.

5 participants