-
Notifications
You must be signed in to change notification settings - Fork 3.7k
enh(python) Add support for unicode identifiers #3280
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
Merged
joshgoebel
merged 10 commits into
highlightjs:main
from
austin-schick:add-python-diacritic-support
Sep 1, 2021
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4eb3aab
Add support for diacritics in Python identifiers
austin-schick 009ffd8
Update Python diacritic support approach based on other unicode discu…
austin-schick b3587eb
Update changelog
austin-schick 62e64d5
Add performance testing scripts
austin-schick 9e5cc01
Rebuild hljs before each perf test
austin-schick e7735b8
run from root dir, be just a bit faster
joshgoebel f11d3e2
fixup basic unicode support for Python
joshgoebel 4ebeefd
Merge branch 'main' into add-python-diacritic-support
joshgoebel 12e382b
simplify ONLY_LANGUAGES
joshgoebel 228e67a
clean up perf tests
joshgoebel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<span class="hljs-keyword">def</span> <span class="hljs-title function_">fóö</span>(): | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-keyword">def</span> <span class="hljs-title function_">bär</span>(): | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-keyword">def</span> <span class="hljs-title function_">FOÖ</span>(): | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-keyword">def</span> <span class="hljs-title function_">ÿay</span>(): | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-keyword">class</span> <span class="hljs-title class_">fóö</span>(): | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-keyword">class</span> <span class="hljs-title class_">bär</span>(): | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-keyword">class</span> <span class="hljs-title class_">FOÖ</span>(): | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-keyword">class</span> <span class="hljs-title class_">ÿay</span>(): | ||
<span class="hljs-keyword">pass</span> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
def fóö(): | ||
pass | ||
|
||
def bär(): | ||
pass | ||
|
||
def FOÖ(): | ||
pass | ||
|
||
def ÿay(): | ||
pass | ||
|
||
class fóö(): | ||
pass | ||
|
||
class bär(): | ||
pass | ||
|
||
class FOÖ(): | ||
pass | ||
|
||
class ÿay(): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env node | ||
const execSync = require('child_process').execSync; | ||
const fs = require('fs'); | ||
const { performance } = require('perf_hooks'); | ||
|
||
const build = () => { | ||
console.log(`Starting perf tests, building hljs ... `); | ||
// build node.js version of library with CJS and ESM libraries | ||
execSync('npm run build', { | ||
cwd: '.', | ||
env: Object.assign( | ||
process.env | ||
) | ||
}); | ||
}; | ||
|
||
const timeTest = (name, func) => { | ||
process.stdout.write(` running ${name}...`); | ||
const t0 = performance.now(); | ||
func(); | ||
const t1 = performance.now(); | ||
console.log(` done! [${((t1 - t0) / 1000).toFixed(2)}s elapsed]`); | ||
} | ||
|
||
const oneLanguageMarkupTests = (lang) => { | ||
for (let i = 0; i < 50; i++) { | ||
execSync('npx mocha ./test/markup', { | ||
cwd: '.', | ||
env: Object.assign( | ||
process.env, | ||
{ ONLY_LANGUAGES: lang } | ||
) | ||
}); | ||
} | ||
}; | ||
|
||
const oneLanguageCheckAutoDetect = (lang) => { | ||
for (let i = 0; i < 50; i++) { | ||
execSync('node ./tools/checkAutoDetect.js', { | ||
env: Object.assign( | ||
process.env, | ||
{ ONLY_LANGUAGES: lang } | ||
) | ||
}); | ||
} | ||
}; | ||
|
||
const globalCheckAutoDetect = () => { | ||
for (let i = 0; i < 5; i++) { | ||
execSync('node ./tools/checkAutoDetect.js'); | ||
} | ||
}; | ||
|
||
const highlightFile = (lang) => { | ||
const source = fs.readFileSync(`./tools/sample_files/${lang}.txt`, { encoding:'utf8' }); | ||
const hljs = require('../build'); | ||
for (let i = 0; i < 2000; i++) { | ||
hljs.highlight(source, {language: lang}); | ||
} | ||
}; | ||
|
||
const main = (lang) => { | ||
build(); | ||
timeTest(`global checkAutoDetect`, globalCheckAutoDetect); | ||
timeTest(`${lang}-only markup tests`, () => oneLanguageMarkupTests(lang)); | ||
timeTest(`${lang}-only checkAutoDetect`, () => oneLanguageCheckAutoDetect(lang)); | ||
timeTest(`highlight large file`, () => highlightFile(lang)); | ||
}; | ||
|
||
main('python'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.