Skip to content

Commit 1801e5e

Browse files
authored
Merge pull request #3031 from masatake/markdown--skip-frontmatter
Markdown: skip frontmatter area
2 parents 298387a + a679933 commit 1801e5e

File tree

9 files changed

+88
-16
lines changed

9 files changed

+88
-16
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--sort=no
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
About this input input.md /^# About this input$/;" c
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Python
3+
draft: false
4+
date: 2021-05-16T13:15:31-05:00
5+
tags: ['code','python']
6+
menu:
7+
main:
8+
parent: 'code'
9+
---
10+
11+
# About this input
12+
13+
This input is taken from #3027 at github submitted by @rickalex21.

main/trace.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,20 @@ bool isMainTraced(void)
117117
return tracingMain;
118118
}
119119

120+
#else
121+
bool isTraced (void) { return false; }
122+
void traceLanguage (langType language) {}
123+
bool isLanguageTraced (langType language) { return false; }
124+
125+
void traceEnter(const char * szFunction,const char * szFormat,...) {}
126+
void traceLeave(const char * szFunction,const char * szFormat,...) {}
127+
void tracePrint(const char * szFunction,const char * szFormat,...) {}
128+
129+
void tracePrintPrefix(const char * szFunction) {}
130+
void tracePrintFmt(const char * szFormat,...) {}
131+
void tracePrintNewline(void) {}
132+
133+
void traceMain(void);
134+
bool isMainTraced(void) { return false; }
135+
120136
#endif // DO_TRACING

main/trace.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@
2525
#define DO_TRACING
2626
#endif
2727

28-
#ifdef DO_TRACING
28+
bool isTraced (void);
29+
void traceLanguage (langType language);
30+
bool isLanguageTraced (langType language);
31+
32+
void traceEnter(const char * szFunction,const char * szFormat,...);
33+
void traceLeave(const char * szFunction,const char * szFormat,...);
34+
void tracePrint(const char * szFunction,const char * szFormat,...);
2935

30-
bool isTraced (void);
31-
void traceLanguage (langType language);
32-
bool isLanguageTraced (langType language);
36+
void tracePrintPrefix(const char * szFunction);
37+
void tracePrintFmt(const char * szFormat,...);
38+
void tracePrintNewline(void);
3339

34-
void traceEnter(const char * szFunction,const char * szFormat,...);
35-
void traceLeave(const char * szFunction,const char * szFormat,...);
36-
void tracePrint(const char * szFunction,const char * szFormat,...);
40+
void traceMain(void);
41+
bool isMainTraced(void);
3742

38-
void tracePrintPrefix(const char * szFunction);
39-
void tracePrintFmt(const char * szFormat,...);
40-
void tracePrintNewline(void);
43+
#ifdef DO_TRACING
4144

4245
#define TRACE_ENTER() traceEnter(__func__,"")
4346
#define TRACE_LEAVE() traceLeave(__func__,"")
@@ -75,9 +78,6 @@
7578
} \
7679
} while(0)
7780

78-
void traceMain(void);
79-
bool isMainTraced(void);
80-
8181
#else //!DO_TRACING
8282

8383
#define TRACE_ENTER() do { } while(0)

misc/enumstr.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#
2121
# Usage:
2222
#
23-
# ./enumstr.sh <input-file> <enum-name> <fname> [PREFIX_FOR_TRIMMING] [--use-lower-bits-as-is]
23+
# ./enumstr.sh <input-file> <enum-name> <funname> [PREFIX_FOR_TRIMMING] [--use-lower-bits-as-is]
2424
#
2525
# Example:
2626
#
@@ -33,7 +33,7 @@ printf '{ /* Generated by misc/enumstr.sh with cmdline:\n'
3333
printf ' %s */\n' "$*"
3434
echo ' switch (e)'
3535
echo ' {'
36-
./ctags --quiet --options=NONE --sort=no -o - --languages=C --kinds-C=e -x --_xformat="%N enum:%s" $1 | grep $2 | while read N S; do
36+
./ctags --quiet --options=NONE --sort=no -o - --languages=C --kinds-C=e --map-C=.h -x --_xformat="%N enum:%s" $1 | grep $2 | while read N S; do
3737
n=$N
3838
if [ -n "$4" ]; then
3939
n=${N#$4}

optlib/markdown.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static void initializeMarkdownParser (const langType language)
4242
" } def\n"
4343
"}}");
4444

45+
addLanguageRegexTable (language, "frontmatter");
4546
addLanguageRegexTable (language, "main");
4647
addLanguageRegexTable (language, "main_sharp");
4748
addLanguageRegexTable (language, "chapter");
@@ -63,6 +64,18 @@ static void initializeMarkdownParser (const langType language)
6364
addLanguageRegexTable (language, "codeblockBacktick");
6465
addLanguageRegexTable (language, "codeblockTildes");
6566

67+
addLanguageTagMultiTableRegex (language, "frontmatter",
68+
"^(---[\n]).*(---[\n])",
69+
"", "", "{tjump=main}", NULL);
70+
addLanguageTagMultiTableRegex (language, "frontmatter",
71+
"^(;;;[\n]).*(;;;[\n])",
72+
"", "", "{tjump=main}", NULL);
73+
addLanguageTagMultiTableRegex (language, "frontmatter",
74+
"^(\\+\\+\\+[\n]).*(\\+\\+\\+[\n])",
75+
"", "", "{tjump=main}", NULL);
76+
addLanguageTagMultiTableRegex (language, "frontmatter",
77+
"^.",
78+
"", "", "{_advanceTo=0start}{tjump=main}", NULL);
6679
addLanguageTagMultiTableRegex (language, "main",
6780
"^#",
6881
"", "", "{_advanceTo=0start}{tjump=main_sharp}", NULL);

optlib/markdown.ctags

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
} def
6161
}}
6262

63+
--_tabledef-Markdown=frontmatter
6364
--_tabledef-Markdown=main
6465
--_tabledef-Markdown=main_sharp
6566
--_tabledef-Markdown=chapter
@@ -99,6 +100,24 @@
99100
--_mtable-regex-Markdown=code/^[ \t]*````*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^`\n]*[\n]//{tenter=codeblockBacktick}{_guest=\1,0end,}
100101
--_mtable-regex-Markdown=code/^[ \t]*~~~~*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^~\n]*[\n]//{tenter=codeblockTildes}{_guest=\1,0end,}
101102

103+
#
104+
# Frontmatter
105+
#
106+
# https://gohugo.io/content-management/front-matter/
107+
#
108+
109+
# YAML area
110+
--_mtable-regex-Markdown=frontmatter/(---[\n]).*(---[\n])//{tjump=main}
111+
112+
# JSON area
113+
--_mtable-regex-Markdown=frontmatter/(;;;[\n]).*(;;;[\n])//{tjump=main}
114+
115+
# TOML area
116+
--_mtable-regex-Markdown=frontmatter/(\+\+\+[\n]).*(\+\+\+[\n])//{tjump=main}
117+
118+
# No frontmatter
119+
--_mtable-regex-Markdown=frontmatter/.//{_advanceTo=0start}{tjump=main}
120+
102121

103122
#
104123
# Main

parsers/yaml.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "parse.h"
2020
#include "read.h"
2121
#include "subparser.h"
22+
#include "trace.h"
2223
#include "types.h"
2324
#include "yaml.h"
2425

@@ -148,8 +149,16 @@ static void findYamlTags (void)
148149
leaveSubparser ();
149150
}
150151

151-
verbose("yaml token:%s<%d>@Line:%"PRIuPTR"\n", tokenTypeName[token.type], token.type,
152+
TRACE_PRINT("yaml token:%s<%d>@Line:%"PRIuPTR"", tokenTypeName[token.type], token.type,
152153
token.start_mark.line + 1);
154+
if (isTraced() && token.type == YAML_SCALAR_TOKEN)
155+
{
156+
TRACE_PRINT_FMT(" ");
157+
for (size_t i = 0; i < token.data.scalar.length; i++)
158+
TRACE_PRINT_FMT("%c", token.data.scalar.value[i]);
159+
TRACE_PRINT_NEWLINE();
160+
}
161+
153162
if (token.type == YAML_STREAM_END_TOKEN)
154163
done = true;
155164

0 commit comments

Comments
 (0)