-
Notifications
You must be signed in to change notification settings - Fork 4
GANReviewTool: TemplateFinder #269
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
+991
−316
Merged
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d8890ea
GANReviewTool: TemplateFinder
bhsd-harry d51b3c6
GANReviewTool: remove unused code
bhsd-harry 570931d
Merge branch 'master' into template
NovemLinguae e1bb931
move constructor to the top of the class
NovemLinguae 60741a4
remove old comment
NovemLinguae 892f551
add some tests
NovemLinguae 22fe5c1
fix
NovemLinguae c63e888
fix
NovemLinguae 07f1067
fix
NovemLinguae 7fe735c
fix
NovemLinguae adf63ef
fix linter errors
NovemLinguae 9a668eb
switch back to ??
NovemLinguae f47a8b6
add some tests demonstrating the power of the new library
NovemLinguae 62a21fa
Rename 'root' to 'wikiPage' in TemplateFinder
bhsd-harry 1520a24
Add comment about Wikipedia extension tags
bhsd-harry 269c4ab
Merge branch 'master' into template
NovemLinguae df6bd79
fix tests
NovemLinguae c1fce96
these look like dev dependencies
NovemLinguae b33c512
Merge branch 'master' into template
NovemLinguae 3eeee55
remove comma
NovemLinguae 1c867b5
remove comment
NovemLinguae 7109d54
Use esbuild to bundle JS files
bhsd-harry 7d03cf2
Update publish.php
bhsd-harry 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import Parser from 'wikiparser-template'; | ||
|
|
||
| Parser.config = { | ||
bhsd-harry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ext: [ | ||
| 'pre', | ||
| 'nowiki', | ||
| 'gallery', | ||
| 'indicator', | ||
| 'langconvert', | ||
| 'graph', | ||
| 'timeline', | ||
| 'hiero', | ||
| 'charinsert', | ||
| 'ref', | ||
| 'references', | ||
| 'inputbox', | ||
| 'imagemap', | ||
| 'source', | ||
| 'syntaxhighlight', | ||
| 'poem', | ||
| 'categorytree', | ||
| 'section', | ||
| 'score', | ||
| 'templatestyles', | ||
| 'templatedata', | ||
| 'math', | ||
| 'ce', | ||
| 'chem', | ||
| 'maplink', | ||
| 'mapframe', | ||
| 'page-collection', | ||
| 'phonos' | ||
| ] | ||
| }; | ||
|
|
||
| export default Parser; | ||
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 |
|---|---|---|
| @@ -1,10 +1,57 @@ | ||
| // TODO: A couple of recent bugs will require a lexer or template parser type class to solve. | ||
| import Parser from './Parser.js'; | ||
|
|
||
| class TemplateFinder { | ||
| // getTemplateList() | ||
| // appendParameter() | ||
| // addWikitextAfterTemplate() | ||
| // getWikitext() | ||
| export class TemplateFinder { | ||
| constructor( wikicode ) { | ||
| this.root = Parser.parse( wikicode, false, 2 ); | ||
bhsd-harry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // appends/adds need to shift all the position variables by the length of the append/add | ||
| } | ||
| static removePrefix( templateName ) { | ||
| return templateName.replace( /^Template:/, '' ); | ||
| } | ||
|
|
||
| getWikitext() { | ||
| return String( this.root ); | ||
| } | ||
|
|
||
| firstTemplate( templateNameRegExOrArrayCaseInsensitive ) { | ||
| let filter; | ||
| if ( !templateNameRegExOrArrayCaseInsensitive ) { | ||
| filter = () => true; | ||
| } else if ( Array.isArray( templateNameRegExOrArrayCaseInsensitive ) ) { | ||
| const templateNameArray = templateNameRegExOrArrayCaseInsensitive | ||
| .map( ( name ) => name.toLowerCase().replace( /\s/g, '_' ) ); | ||
| filter = ( { name } ) => templateNameArray.includes( TemplateFinder.removePrefix( name ).toLowerCase() ); | ||
| } else { | ||
| const regEx = new RegExp( `^Template:${ templateNameRegExOrArrayCaseInsensitive }$`, 'i' ); | ||
| filter = ( { name } ) => regEx.test( name.replace( /_/g, ' ' ) ); | ||
| } | ||
| return this.root.querySelectorAll( 'template' ).find( filter ); | ||
| } | ||
|
|
||
| firstTemplateInsertCode( templateNameRegExOrArrayCaseInsensitive, codeToInsert ) { | ||
| const template = this.firstTemplate( templateNameRegExOrArrayCaseInsensitive ); | ||
| if ( template ) { | ||
| template.append( `${ codeToInsert.replace( /^\|/, '' ) }\n` ); | ||
| } | ||
| } | ||
|
|
||
| firstTemplateGetParameterValue( templateNameRegExOrArrayCaseInsensitive, parameter ) { | ||
| const template = this.firstTemplate( templateNameRegExOrArrayCaseInsensitive ); | ||
| if ( !template ) { | ||
| return null; | ||
| } | ||
| return template.getValue( parameter ) ?? null; | ||
| } | ||
|
|
||
| firstTemplateDeleteParameter( templateNameRegExOrArrayCaseInsensitive, parameter ) { | ||
| const template = this.firstTemplate( templateNameRegExOrArrayCaseInsensitive ); | ||
| if ( template ) { | ||
| for ( const token of template.getAllArgs() ) { | ||
| if ( token.name.toLowerCase() === parameter ) { | ||
| token.remove(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.