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 for underscores in Python numbers #3038 #3039

Merged
merged 2 commits into from Aug 16, 2021
Merged

Support for underscores in Python numbers #3038 #3039

merged 2 commits into from Aug 16, 2021

Conversation

@marvintensuan
Copy link
Contributor

@marvintensuan marvintensuan commented Aug 16, 2021

Modified the regex for number in prism-python.js from:

'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?j?\b/i,

to:

/(?:\b(?=\d)|\B(?=\.))(?:0[bo](_)?)?(?:(?:\d|0x(_)?[\da-f])([\da-f]|[\da-f]_)*(?:\.\d*)?|\.\d+|((\d+_)*(\.)?(\d+)?)*)(?:e[+-]?\d+)?([^_]j)?\b/i

I have highlighted the rationale at #3038. Additional test cases were also added.


Test results:

> prismjs@1.24.1 test:languages (...)\prism
> mocha tests/run.js "--language=python"



  Testing language 'python'
    √ – should pass test case 'boolean_feature'
    √ – should pass test case 'builtin_feature'
    √ – should pass test case 'class-name_feature'
    √ – should pass test case 'comment_feature'
    √ – should pass test case 'decorator_feature'
    √ – should pass test case 'function_feature'
    √ – should pass test case 'issue1355'
    √ – should pass test case 'keyword_feature'
    √ – should pass test case 'number_feature'
    √ – should pass test case 'operator_feature'
    √ – should pass test case 'string-interpolation_feature'
    √ – should pass test case 'string_feature'
    √ – should pass test case 'triple-quoted-string_feature'


  13 passing (101ms)
@github-actions
Copy link

@github-actions github-actions bot commented Aug 16, 2021

JS File Size Changes (gzipped)

A total of 1 files have changed, with a combined diff of +13 B (+1.2%).

file master pull size diff % diff
components/prism-python.min.js 1.05 KB 1.06 KB +13 B +1.2%

Generated by 🚫 dangerJS against c56db5a

Loading

@marvintensuan marvintensuan changed the title Support for underscores in Python numbers #3038 Support for underscores in Python numbers resolve #3038 Aug 16, 2021
@marvintensuan marvintensuan changed the title Support for underscores in Python numbers resolve #3038 Support for underscores in Python numbers #3038 Aug 16, 2021
@RunDevelopment RunDevelopment linked an issue that may be closed by this pull request Aug 16, 2021
Copy link
Member

@RunDevelopment RunDevelopment left a comment

Thank you for the PR @marvintensuan!

I have a suggestion. Also, please rebuild Prism by running npm run build and committing the changes to prism-python.min.js.

Loading

components/prism-python.js Outdated Show resolved Hide resolved
Loading
@RunDevelopment RunDevelopment merged commit 6f5d68f into PrismJS:master Aug 16, 2021
11 checks passed
Loading
@RunDevelopment
Copy link
Member

@RunDevelopment RunDevelopment commented Aug 16, 2021

Thank you for contributing @marvintensuan!

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants