{"id":18238181,"url":"https://github.com/mehdihadeli/syntaxhighlighter","last_synced_at":"2026-01-28T15:31:14.284Z","repository":{"id":260779144,"uuid":"882305192","full_name":"mehdihadeli/SyntaxHighlighter","owner":"mehdihadeli","description":"A powerful Syntax Highlighting library inspired by Pygments and Chroma, designed for versatility and ease of use.","archived":false,"fork":false,"pushed_at":"2024-11-04T00:53:28.000Z","size":122,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T12:35:41.529Z","etag":null,"topics":["bbcode","console","csharp","dotnet","highlighting","html","syntax","syntax-highlighter","syntax-highlighting"],"latest_commit_sha":null,"homepage":"","language":"C#","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/mehdihadeli.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":"2024-11-02T13:18:36.000Z","updated_at":"2025-01-06T14:22:32.000Z","dependencies_parsed_at":"2025-02-14T12:31:38.237Z","dependency_job_id":"543b3aee-6b2a-414b-943c-f96ab2ffa35a","html_url":"https://github.com/mehdihadeli/SyntaxHighlighter","commit_stats":null,"previous_names":["mehdihadeli/syntaxhighlighter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdihadeli%2FSyntaxHighlighter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdihadeli%2FSyntaxHighlighter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdihadeli%2FSyntaxHighlighter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdihadeli%2FSyntaxHighlighter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehdihadeli","download_url":"https://codeload.github.com/mehdihadeli/SyntaxHighlighter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247878023,"owners_count":21011158,"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":["bbcode","console","csharp","dotnet","highlighting","html","syntax","syntax-highlighter","syntax-highlighting"],"created_at":"2024-11-05T03:04:16.649Z","updated_at":"2026-01-28T15:31:14.246Z","avatar_url":"https://github.com/mehdihadeli.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Syntax Highlighter\n\nA powerful `Syntax Highlighting` library inspired by [Pygments](https://github.com/pygments/pygments) and [Chroma](https://github.com/alecthomas/chroma), designed for versatility and ease of use. \n\nThis library allows you to define styles, formatters, lexers, and tokens for highlighting code snippets across various programming languages.\n\n## Features\n\n- **Lexer Support**: Easily create lexers for different programming languages.\n- **Styles**: You can define and use styles based on a [JSON file](./src/Styles/dracula.json), with configurations based on token types. This allows you to customize the appearance of highlighted code elements, such as keywords, strings, and comments, enhancing readability and visual appeal.\n- **Formatters**: Format highlighted code output in various ways (HTML, terminal, bbcode, etc.).\n- **Tokenization**: Break down source code into meaningful tokens for better syntax highlighting.\n\n## Installation\nTODO..\n\n## Usage\nHere is a quick guide on how to use the syntax highlighter in your project.\n\nC#  syntax highlighter sample:\n```csharp\n\nstring csharpSourceCode =\n    @\"```csharp\nusing System;\n\nnamespace SampleNamespace\n{\n    public class SampleClass\n    {\n        // A constant\n        const int MaxValue = 100;\n\n        // Entry point of the program\n        static void Main(string[] args)\n        {\n            // Declare variables\n            int number = 10;\n            bool isEven = (number % 2 == 0);\n            \n            // Output\n            Console.WriteLine($\"\"Is the number {number} even? {isEven}\"\");\n\n            // Loop\n            for (int i = 0; i \u003c MaxValue; i++)\n            {\n                Console.WriteLine(i);\n            }\n\n            // Function call\n            DoSomething();\n        }\n    }\n}\";\n\nLexer lexer = new CSharpLexer();\nFormatter formatter = new ConsoleFormatter256();\nvar style = await Style.LoadThemeByName(\"dracula\");\n\nvar tokens = lexer.Tokenize(csharpSourceCode);\nformatter.Format(tokens, Console.Out, style);\nConsole.WriteLine(); \n\nConsole.ReadKey();\n```\n\n![](assets/csharp.png)\n\n\nGolang syntax highlighter sample:\n\n```csharp\nstring goSourceCode =\n    @\"```go\npackage main\n\nimport (\n\t\"\"fyne.io/fyne/v2/app\"\"\n\t\"\"fyne.io/fyne/v2/container\"\"\n\t\"\"fyne.io/fyne/v2/widget\"\"\n)\n\nfunc main() {\n\tmyApp := app.New()\n\tmyWindow := myApp.NewWindow(\"\"Opacity Example\"\")\n\n    int i:= 1\n\n\t// Create a container with a semi-transparent background\n\tcontent := container.NewVBox(\n\t\twidget.NewLabel(\"\"This is some text with a semi-transparent background\"\"),\n\t)\n\n\t// Setting a custom background color with opacity\n\tcontent.SetBackgroundColor(fyne.NewColor(255, 0, 0, 128)) // RGBA\n\n\tmyWindow.SetContent(content)\n\tmyWindow.ShowAndRun()\n}\n```\";\n\nLexer lexer = new GoLexer();\nFormatter formatter = new ConsoleFormatter256();\nvar style = await Style.LoadThemeByName(\"dracula\");\n\nvar tokens = lexer.Tokenize(goSourceCode);\nformatter.Format(tokens, Console.Out, style);\nConsole.WriteLine(); \n\nConsole.ReadKey();\n```\n![](assets/golang.png)\n\n\n## Lexers\n\nLexers are responsible for breaking down the code into tokens. You can create a custom lexer by extending the Lexer class.\n\n```csharp\npublic class NewLanguageLexer : Lexer\n{\n    // Implement required methods here\n}\n```\n\n## Style\n\nYou can create and use custom style themes through a [JSON file](src/Styles/dracula.json), which allows for flexible configuration of the appearance of highlighted code. An example of a default theme is dracula.json, which might look like this:\n\n```json\n{\n  \"name\": \"Dracula\",\n  \"foreground\": \"#f8f8f2\",\n  \"background\": \"#44475a\",\n  \"margin\": 2,\n  \"styles\": {\n    \"keyword\": {\n      \"foreground\": \"#8be9fd\",\n      \"bold\": true\n    },\n    \"comment\": {\n      \"foreground\": \"#6272a4\",\n      \"italic\": true\n    }\n    // Additional token styles...\n  }\n}\n\n```\n\nIn this structure, you can define specific styles based on token types (like `keyword` and `comment`), customizing attributes such as colors and font weights. \nThis enables users to enhance the readability and aesthetic appeal of syntax-highlighted content according to their preferences.\n\n## Supported Languages\n\n- [x] C#\n- [x] Golang\n- [ ] Rust\n- [ ] Java\n- [ ] Typescript\n- [ ] Javascript\n- [ ] Python\n\n## Contributing\nContributions are welcome! If you would like to contribute to the project, please fork the repository and submit a pull request.\n\n## License\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehdihadeli%2Fsyntaxhighlighter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehdihadeli%2Fsyntaxhighlighter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehdihadeli%2Fsyntaxhighlighter/lists"}