{"id":17031422,"url":"https://github.com/halirutan/wolframlanguage-google-prettify","last_synced_at":"2025-04-23T22:00:51.153Z","repository":{"id":144846851,"uuid":"186254175","full_name":"halirutan/WolframLanguage-Google-Prettify","owner":"halirutan","description":"Wolfram Language support for Google Code Prettify","archived":false,"fork":false,"pushed_at":"2019-05-13T14:05:23.000Z","size":4023,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T03:51:11.941Z","etag":null,"topics":["highlighting","javascript","wolfram-language","wolfram-mathematica"],"latest_commit_sha":null,"homepage":"https://halirutan.github.io/WolframLanguage-Google-Prettify/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/halirutan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-12T12:48:31.000Z","updated_at":"2025-01-01T06:24:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"7b2ccfcb-aed2-4b11-9d0c-24e4de4ab247","html_url":"https://github.com/halirutan/WolframLanguage-Google-Prettify","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halirutan%2FWolframLanguage-Google-Prettify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halirutan%2FWolframLanguage-Google-Prettify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halirutan%2FWolframLanguage-Google-Prettify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halirutan%2FWolframLanguage-Google-Prettify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/halirutan","download_url":"https://codeload.github.com/halirutan/WolframLanguage-Google-Prettify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250522299,"owners_count":21444511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["highlighting","javascript","wolfram-language","wolfram-mathematica"],"created_at":"2024-10-14T08:24:09.097Z","updated_at":"2025-04-23T22:00:51.043Z","avatar_url":"https://github.com/halirutan.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wolfram Language support for the Google Code Prettify\n \nThis is the official code highlighter for [Mathematica.stackexchange.com](http://mathematica.stackexchange.com/)\nand [the Wolfram Community](http://community.wolfram.com). It provides the syntax specification\nfor the Wolfram Language required to highlight code with the [Google code prettifier](https://github.com/google/code-prettify). Here is a highlighted example from StackExchange:\n\n\u003e ![Sample Image](sample.png)\n\n## Usage\n\nTo use it with your installation of [google-code-prettify](https://github.com/google/code-prettify), you have to add the minified JavaScript language definition `lang-mma.min.js` from the `JSHighlighter` directory to your code-prettify installation.\nAnother way is to load the Wolfram Language highlighter after code-prettify in your HTML code.\nThe `JSHighlighter` directory contains an `index.html` that [shows how it works](https://halirutan.github.io/WolframLanguage-Google-Prettify/JSHighlighter/index.html).\nFurther information can be found in the [google-code-prettify repository](https://github.com/google/code-prettify).\n\n## Building and Development\n\nThe Wolfram Language highlighting script is created from the `JSHighlighter/lang-mma-TEMPLATE.js` template by inserting\nregexes for Mathematica built-in symbols and named characters.\nThis can be done entirely from within Mathematica by using the provided package:\n\n```mma\nPacletDirectoryAdd[\"/YourPath/WolframLanguage-Google-Prettify/WLSource/SymbolInformation\"];\n\u003c\u003c SymbolInformation`\n\nbuildJavaScriptTrieRegex[]\n(* or *)\nbuildJavaScriptAlternativeRegex[]\n```\n\nIt's vital to leave the `SymbolInformation` package in the repository directory (aka don't install it) because it relies\non the relative path to find the correct `JSHighlighter` directory. Alternatively, you can provide the path to\n`lang-mma-TEMPLATE.js` as an argument to the two functions. The difference between the two building methods is\n\n- `buildJavaScriptAlternativeRegex[]` takes the list of Mathematica's built-in symbols and creates a regex using the alternative pattern. Therefore, the list of symbols `{\"Names\", \"NamespaceBox\", \"NamespaceBoxOptions\"}` becomes the regex \n`(:?Names|NamespaceBox|NamespaceBoxOptions)` which is then inserted in the template JavaScript. This approach was used in former versions of the highlighter.\n- `buildJavaScriptTrieRegex[]` takes the list of Mathematica's built-in symbols and builds a \n[Trie](https://en.wikipedia.org/wiki/Trie) which should *in theory* improve the performance of matching symbols. Therefore, the list of symbols `{\"Names\", \"NamespaceBox\", \"NamespaceBoxOptions\"}` becomes a regex of the form `Names(?:paceBox(?:Options)?)?`.\n\nIt's up to you, which version you want to use and I have set up two performance test-pages which display all 7000 Mathematica\nsymbols and 7000 dictionary words (as negative examples) to profile the matching speed.\nThe vast majority of the time is not spent in the matching though and if my not entirely mistaken with my non-existent JavaScript\nprofiling knowledge, only 4.7ms of 1483ms is spent in the actual regex:\n\n[![Profiling](profiling.png)](profiling.png)\n\nSurprisingly, the `(:?Names|NamespaceBox|NamespaceBoxOptions)` alternative pattern is 1ms faster.\nThis difference is not noticeable and since the `lang-mma.min.js` Trie version (88kB) is much smaller than the alternative pattern\n`lang-mma-alternative-regex.min.js` (127kB), I would suggest to use the Trie version. However, if readability counts because\nyou want to check easily if a symbol is included in the regex, then the alternative pattern version is to be preferred.\nYou can perform your own performance tests by using\n\n- [this page](https://halirutan.github.io/WolframLanguage-Google-Prettify/JSHighlighter/performance-page-trie-regex.html) for testing the Trie version of the regex\n- [this page](https://halirutan.github.io/WolframLanguage-Google-Prettify/JSHighlighter/performance-page-alternative-regex.html) for using the alternative pattern version of the regex\n\n### Repository Structure\n\n- `JSHighlighter` directory contains the template JavaScript files, the final syntax highlighter scripts and their minified versions, CSS definitions for StackExchange code colors, and example HTML pages.\n- `WLSource` contains the `SymbolInformation` Mathematica package to extract built-in symbols and named characters and build the final highlighter scripts. To build a Trie from a list of words, the `SymbolInformation` package uses `JLink` code which is provided as a `jar` in the `Java` subdirectory. This jar is built from ...\n- ... the `KotlinSource` which contains a small `PrefixTree.kt` for building a Trie and turning it into a regex. Additionally,\nthis directory contains test-code for profiling the matching speed.\n\nThe `SymbolInformation` package exposes some additional functions.\nYou can e.g. create a Trie regex from a list of words:\n\n```mma\nl = Names[\"Plot*\"];\ncreateTrieRegex[l]\n\n(* \"Plot(?:3(?:D|Matrix)|Division|Joined|L(?:a(?:bel(?:s)?|yout)|egends)|Markers|Points|R(?:ange(?:Clip(?:PlanesStyle|ping)|Padding)?|egion)|Style|Theme)?\" *)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalirutan%2Fwolframlanguage-google-prettify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalirutan%2Fwolframlanguage-google-prettify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalirutan%2Fwolframlanguage-google-prettify/lists"}