开源软件名称(OpenSource Name):ali-rantakari/peg-markdown-highlight开源软件地址(OpenSource Url):https://github.com/ali-rantakari/peg-markdown-highlight开源编程语言(OpenSource Language):C 56.8%开源软件介绍(OpenSource Introduction):PEG Markdown HighlightCopyright 2011-2016 Ali Rantakari -- http://hasseg.org This is a syntax highlighter for the Markdown language, designed to be integrated into GUI text editor programs. It uses a recursive-descent parser for interpreting the input (instead of e.g. regular expressions), and this parser is based on the PEG grammar from John MacFarlane's peg-markdown project. PEG Markdown Highlight…
This program uses the PEG grammar from John MacFarlane's Thanks to these gentlemen (and everyone who contributed to their projects) for making this one possible. See the Why This is UsefulExisting syntax highlighting solutions in (programming) editors are too simple to be able to handle the context sensitivity of the Markdown language, and the fact that it is not well defined. They usually work well for simple cases but fail for many nontrivial inputs that existing Markdown compilers handle correctly. This project is an attempt to bring Markdown syntax highlighting to the same level of “correctness” as the existing compilers. Quick Code ExamplesHere are some quick, simple examples of what it might look like to use this highlighter in your project. Using the Cocoa highlighter classes to highlight an NSTextView with default settings: #import "HGMarkdownHighlighter.h"
@interface MyClass : NSObject {
HGMarkdownHighlighter *highlighter;
}
- (void) awakeFromNib {
highlighter = [[HGMarkdownHighlighter alloc]
initWithTextView:myTextView];
[highlighter activate];
} Manually highlighting a TextWidget in some hypothetical GUI framework: #include "pmh_parser.h"
void highlight(TextWidget *textWidget)
{
pmh_element **results;
pmh_markdown_to_elements(textWidget->containedText, pmh_EXT_NONE, &results);
for (int i = 0; i < pmh_NUM_LANG_TYPES; i++) {
TextStyle style;
switch (i) {
case pmh_EMPH: style = ItalicStyle; break;
case pmh_STRONG: style = BoldStyle; break;
case pmh_H1: style = LargeFontStyle; break;
default: style = FunkyStyle; break;
}
pmh_element *element_cursor = results[i];
while (element_cursor != NULL) {
textWidget->setStyleForSpan(element_cursor->pos,
element_cursor->end,
style);
element_cursor = element_cursor->next;
}
}
pmh_free_elements(results);
} Repo ContentsThis project contains:
API DocumentationThe public APIs are documented using Doxygen. If you have it installed,
just run Using the Parser in Your ApplicationThe parser has been written in ANSI/ISO C89 with GNU extensions, which means
that you need a GCC-compatible compiler (see section on MSVC below, though).
You also need Bourne Shell and some common Unix utilities due to a utility
shell script that is used to combine some files in a Files You NeedYou need to add the following files into your project:
Compiling in Microsoft Visual C++First you need to generate
Whichever way you go, the command you run is MSVC does not support some of the GNU extensions the code uses, but it should
compile it nicely as C++ (just change the extensions to
Stylesheet ParserThe The stylesheet syntax is documented in |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论