diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b2b0a80..0000000 --- a/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -# temporary compile results -*.o - -# Binary excutions -mdp -mdp.exe - -# Other temporary files -.DS_Store -*~ -*.swp -*.sublime-workspace -*.out -tags diff --git a/AUTHORS b/AUTHORS index 3330634..04b9550 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,4 +13,5 @@ mnalt guobin2312 lukebond +namhyung diff --git a/README.md b/README.md index 9f9fa41..c05f04a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ mdp needs the ncursesw headers to compile. So make sure you have them installed: -- on Cygwin you need `libncursesw10` and `libncurses-devel` - on Raspbian (Raspberry Pi) you need `libncurses5-dev` and `libncursesw5-dev` Now download and install mdp: @@ -22,6 +21,7 @@ $ mdp sample.md - On Arch, you can use the existing [AUR package](https://aur.archlinux.org/packages/mdp-git/). +- on Cygwin you can use the existing [package](https://cygwin.com/cgi-bin2/package-grep.cgi?grep=mdp.exe) from the setup program. - On Debian, you can use the existing [DEB package](https://tracker.debian.org/pkg/mdp-src), or run `apt-get install mdp`. - On FreeBSD, you can use the port [misc/mdp](http://www.freshports.org/misc/mdp). - On OS-X, use the existing [Homebrew Formula](http://brewformulas.org/Mdp) by running `brew install mdp`. diff --git a/include/main.h b/include/main.h index 62e748b..7b21482 100644 --- a/include/main.h +++ b/include/main.h @@ -25,6 +25,6 @@ #define MDP_VER_MAJOR 1 #define MDP_VER_MINOR 0 -#define MDP_VER_REVISION 9 +#define MDP_VER_REVISION 11 #endif // !defined( MAIN_H ) diff --git a/include/markdown.h b/include/markdown.h index 07268dc..e5f3ca5 100644 --- a/include/markdown.h +++ b/include/markdown.h @@ -48,6 +48,7 @@ IS_QUOTE, IS_CODE, IS_TILDE_CODE, + IS_GFM_CODE, IS_HR, IS_UNORDERED_LIST_1, IS_UNORDERED_LIST_2, diff --git a/include/parser.h b/include/parser.h index db95f65..b2ecc21 100644 --- a/include/parser.h +++ b/include/parser.h @@ -59,5 +59,6 @@ int next_blank(cstring_t *text, int i); int next_word(cstring_t *text, int i); int next_nontilde(cstring_t *text, int i); +int next_nonbacktick(cstring_t *text, int i); #endif // !defined( PARSER_H ) diff --git a/mdp.cygport b/mdp.cygport new file mode 100644 index 0000000..af6da10 --- /dev/null +++ b/mdp.cygport @@ -0,0 +1,34 @@ +# package name +NAME="mdp" +VERSION=1.0.9 +RELEASE=1 + +# .hint generation +CATEGORY="Utils" +SUMMARY="A command-line based markdown presentation tool" +DESCRIPTION="A ncurses-based command-line presentation tool, which makes +it easy to create slides using the popular markdown format." + +# source and patch files +SRC_URI="https://github.com/visit1985/mdp/archive/${VERSION}.tar.gz" +DOCS="sample.md" + +# Build dependencies only +DEPEND="gcc-core libncurses-devel make" +# runtime deps to go in setup.hint +#REQUIRES="libncursesw10" + +# custom src_compile, src_install and src_test + +src_compile() { + cd ${S} + cygmake +} + +src_install() { + cd ${S} + PREFIX=/usr cyginstall +} + +src_test() { :; } + diff --git a/sample.md b/sample.md index 4e304c6..502bb2b 100644 --- a/sample.md +++ b/sample.md @@ -115,13 +115,37 @@ becomes ~~~ {.numberLines} -int main(int argc, char \*argv[]) { - printf("%s\\n", "Hello world!"); +int main(int argc, char *argv[]) { + printf("%s\n", "Hello world!"); } ~~~~~~~~~~~~~~~~~~ Pandoc attributes (like ".numberlines" etc.) will be ignored + +------------------------------------------------- + +-> # Supported markdown formatting <- + +You can also use [github](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) flavored markdown's +code block. Use at least three backticks to open +and at least as many or more backticks for closing. + +\``` +\int main(int argc, char \*argv[]) { +\ printf("%s\\n", "Hello world!"); +\} +\``` + +becomes + +``` +int main(int argc, char *argv[]) { + printf("%s\n", "Hello world!"); +} +``` + +Language hint will be ignored ------------------------------------------------- diff --git a/src/parser.c b/src/parser.c index 465bdc1..615cc6e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -158,7 +158,8 @@ slide = next_slide(slide); sc++; - } else if(CHECK_BIT(bits, IS_TILDE_CODE) && + } else if((CHECK_BIT(bits, IS_TILDE_CODE) || + CHECK_BIT(bits, IS_GFM_CODE)) && CHECK_BIT(bits, IS_EMPTY)) { // remove tilde code markers (text->reset)(text); @@ -400,6 +401,7 @@ static int unordered_list_level = 0; static int unordered_list_level_offset[] = {-1, -1, -1, -1}; static int num_tilde_characters = 0; + static int num_backticks = 0; int i = 0; // increment int bits = 0; // markdown bits @@ -444,6 +446,27 @@ if (num_tilde_characters > 0) { SET_BIT(bits, IS_CODE); SET_BIT(bits, IS_TILDE_CODE); + return bits; + } + + // IS_GFM_CODE + if (wcsncmp(text->value, L"```", 3) == 0) { + int backticks_in_line = next_nonbacktick(text, 0); + if (backticks_in_line >= num_backticks) { + if (num_backticks > 0) { + num_backticks = 0; + } else { + num_backticks = backticks_in_line; + } + SET_BIT(bits, IS_EMPTY); + SET_BIT(bits, IS_GFM_CODE); + return bits; + } + } + + if (num_backticks > 0) { + SET_BIT(bits, IS_CODE); + SET_BIT(bits, IS_GFM_CODE); return bits; } @@ -831,3 +854,10 @@ return i; } +int next_nonbacktick(cstring_t *text, int i) { + while ((i < text->size) && text->value[i] == L'`') + i++; + + return i; +} + diff --git a/src/url.c b/src/url.c index 0e49b49..da21a57 100644 --- a/src/url.c +++ b/src/url.c @@ -165,7 +165,7 @@ for (; *i; i++) { if (*i == '\\') { i++; - } else if ( *i == '[' && *(i+1) != ']') { + } else if ( *i == '[' && *(i+1) && *(i+1) != ']') { while (*i && *i != ']') i++; i++; if (*i == '(' && wcschr(i, ')')) { @@ -185,7 +185,7 @@ for (; *i; i++) { if (*i == '\\') { i++; - } else if ( *i == '[' && *(i+1) != ']') { + } else if ( *i == '[' && *(i+1) && *(i+1) != ']') { while (*i && *i != ']') i++; i++; if (*i == '(' && wcschr(i, ')')) { diff --git a/src/viewer.c b/src/viewer.c index c1a4543..20d496d 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -656,7 +656,8 @@ // IS_CODE if(CHECK_BIT(line->bits, IS_CODE)) { - if (!CHECK_BIT(line->bits, IS_TILDE_CODE)) { + if (!CHECK_BIT(line->bits, IS_TILDE_CODE) && + !CHECK_BIT(line->bits, IS_GFM_CODE)) { // set static offset for code offset = CODE_INDENT; }