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

Support additional options for Backtick Code Block #5299

Closed
wants to merge 5 commits into from
Closed

Support additional options for Backtick Code Block #5299

wants to merge 5 commits into from

Conversation

TimonPeng
Copy link

@TimonPeng TimonPeng commented Sep 21, 2023

What does it do?

Support additional options for Backtick Code Block.

Screenshots

Before:

Before

After:

After

Source markdown:

Markdown

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

Issue #4830

Syntax of Backtick Code Block is:

[language] [title] [url] [link text] [additional options]

I was going to simply use split spaces to extract it, but the problem is... If do it with this way, then won't be able to use spaces in the title and link text, which is barely ok, but not what I want.

  1. the first one [language] is sure there's no spaces
  2. the second one [title] might have spaces
  3. the third one [url] must be a link
  4. the fourth one [link text] might have spaces
  5. the fifth one [additional options] must have a colon and probably have spaces

It also would be chaos to matching with regex too, although I did write:

/(\w+)\s+(.+?)\s+(?=http)([\S]+)\s+(.+?)\s+((?:\w+:\S+\s*)+)/

.exec('java title https://google.com google mark:1,4-7,10 wrap:true');

[
  'java title https://google.com google mark:1,4-7,10 wrap:true',
  'java',
  'title',
  'https://google.com',
  'google',
  'mark:1,4-7,10 wrap:true',
  index: 0,
  input: 'java title https://google.com google mark:1,4-7,10 wrap:true',
  groups: undefined
]

.exec('python Backtick Code Syntax https://flask.palletsprojects.com/en/2.3.x/ Flask Docs mark:1,5-7 wrap:true')

[
  'python Backtick Code Syntax https://flask.palletsprojects.com/en/2.3.x/ Flask Docs mark:1,5-7 wrap:true',
  'python',
  'Backtick Code Syntax',
  'https://flask.palletsprojects.com/en/2.3.x/',
  'Flask Docs',
  'mark:1,5-7 wrap:true',
  index: 0,
  input: 'python Backtick Code Syntax https://flask.palletsprojects.com/en/2.3.x/ Flask Docs mark:1,5-7 wrap:true',
  groups: undefined
]

In the end I decided to use the same code logic as the Code Block Plugin(lib/plugins/tag/code.js), which is simpler and easier to synchronise updates and maintain.

@github-actions
Copy link

How to test

git clone -b master https://github.com/TimonPeng/hexo.git
cd hexo
npm install
npm test

@D-Sketon
Copy link
Member

can you add some tests?

@TimonPeng
Copy link
Author

can you add some tests?

Added, it's looks good to you?

@TimonPeng
Copy link
Author

TimonPeng commented Sep 22, 2023

prismjs's mark parameter type is string, so move the array loop to highlightjs file.

https://prismjs.com/plugins/line-highlight/

data-line="1,2-3"

@coveralls
Copy link

Coverage Status

coverage: 98.601% (-0.09%) from 98.687% when pulling fee7615 on TimonPeng:master into ad05652 on hexojs:master.

@uiolee uiolee marked this pull request as draft January 12, 2024 07:23
@uiolee uiolee added the javascript Pull requests that update Javascript code label Jan 12, 2024
@TimonPeng TimonPeng closed this by deleting the head repository Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants