From: Jaroslav Kysela Date: Thu, 5 May 2016 13:25:20 +0000 (+0200) Subject: mdhelp: add support for markdown X-Git-Tag: v4.2.1~574 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c92eeb5662ccd8e204795c9782f5c2995e445513;p=thirdparty%2Ftvheadend.git mdhelp: add support for markdown --- diff --git a/Makefile b/Makefile index 46041e8ff..29c85b0f1 100644 --- a/Makefile +++ b/Makefile @@ -545,10 +545,12 @@ MD-TO-C = PYTHONIOENCODING=utf-8 $(PYTHON) support/doc/md_to_c.py SRCS-yes += src/docs.c I18N-C-DOCS = src/docs_inc.c I18N-DOCS = $(wildcard docs/markdown/*.md) +I18N-DOCS += $(wildcard docs/markdown/inc/*.md) I18N-DOCS += $(wildcard docs/class/*.md) I18N-DOCS += $(wildcard docs/property/*.md) I18N-DOCS += $(wildcard docs/wizard/*.md) MD-ROOT = $(patsubst docs/markdown/%.md,%,$(wildcard docs/markdown/*.md)) +MD-ROOT += $(patsubst docs/markdown/inc/%.md,inc/%,$(wildcard docs/markdown/inc/*.md)) MD-CLASS = $(patsubst docs/class/%.md,%,$(wildcard docs/class/*.md)) MD-PROP = $(patsubst docs/property/%.md,%,$(wildcard docs/property/*.md)) MD-WIZARD = $(patsubst docs/wizard/%.md,%,$(wildcard docs/wizard/*.md)) @@ -684,12 +686,7 @@ $(BUILDDIR)/docs-timestamp: $(I18N-DOCS) support/doc/md_to_c.py $(MD-TO-C) --in="docs/wizard/$${i}.md" \ --name="tvh_doc_wizard_$${i}" >> src/docs_inc.c || exit 1; \ done - @printf "\n\nconst struct tvh_doc_page tvh_doc_markdown_pages[] = {\n" >> src/docs_inc.c - @for i in $(MD-ROOT); do \ - echo " { \"$${i}\", tvh_doc_root_$${i} }," >> src/docs_inc.c || exit 1; \ - done - @echo " { NULL, NULL }," >> src/docs_inc.c || exit 1 - @echo "};" >> src/docs_inc.c + @$(MD-TO-C) --pages="$(MD-ROOT)" >> src/docs_inc.c @touch $@ src/docs_inc.c: $(BUILDDIR)/docs-timestamp diff --git a/docs/class/ipblocking.md b/docs/class/ipblocking.md index 744b943ad..273db2138 100644 --- a/docs/class/ipblocking.md +++ b/docs/class/ipblocking.md @@ -5,32 +5,13 @@ are not allowed to login (use any Tvheadend service). --- -###Menu Bar/Buttons - -The tab has the following buttons: - -Button | Function ------------------------|------------------- -**Save** | Save any changes made to the grid/entries. -**Undo** | Revert any changes made since the last save. -**Add** | Display the *Add IP Blocking Record* dialog. -**Delete** | Delete the selected entry/entries. -**Edit** | Edit the selected entry. -**View Level**| Change the interface view level to show/hide more advanced options. -**Help** | Display this help page. +inc/buttons1 --- -###Adding and Editing an Entry/Record - -To add an entry press the *[Add]* button from the menu bar. - -To edit an entry highlight the desired entry within the grid, and -then press the *[Edit]* button from the menu bar. +inc/add1 -!['Add Record Dialog'](docresources/accessipblockingedit.png) - -Note that both the *[Add]* and *[Edit]* buttons display similar dialogs. +!['Add Entries Dialog'](docresources/accessipblockingedit.png) **Tip**: You can enter a comma-separated list of network prefixes, if you're unsure as to what to enter in the *Network prefix* field take a look at @@ -38,12 +19,6 @@ unsure as to what to enter in the *Network prefix* field take a look at --- -### Deleting an Entry. - -To delete an entry highlight (select) the entry from the grid, then press -the *[Delete]* button from the menu bar. - -**Tip**: Rather than deleting an entry, you can disable it instead by -pressing the *[Edit]* button, and unticking the "Enabled" check box. +inc/del1 --- diff --git a/docs/markdown/inc/add1.md b/docs/markdown/inc/add1.md new file mode 100644 index 000000000..ed62d55ca --- /dev/null +++ b/docs/markdown/inc/add1.md @@ -0,0 +1,8 @@ +###Adding and Editing an Entry/Record + +To add an entry press the *[Add]* button from the menu bar. + +To edit an entry highlight the desired entry within the grid, and +then press the *[Edit]* button from the menu bar. + +Note that both the *[Add]* and *[Edit]* buttons display similar dialogs. diff --git a/docs/markdown/inc/buttons1.md b/docs/markdown/inc/buttons1.md new file mode 100644 index 000000000..4413507b3 --- /dev/null +++ b/docs/markdown/inc/buttons1.md @@ -0,0 +1,13 @@ +###Menu Bar/Buttons + +The tab has the following buttons: + +Button | Function +-----------------------|------------------- +**Save** | Save any changes made to the grid/entries. +**Undo** | Revert any changes made since the last save. +**Add** | Display the *Add entry* dialog. +**Delete** | Delete the selected entry/entries. +**Edit** | Edit the selected entry. +**View Level** | Change the interface view level to show/hide more advanced options. +**Help** | Display this help page. diff --git a/docs/markdown/inc/del1.md b/docs/markdown/inc/del1.md new file mode 100644 index 000000000..65810d2b0 --- /dev/null +++ b/docs/markdown/inc/del1.md @@ -0,0 +1,7 @@ +### Deleting an Entry. + +To delete an entry highlight (select) the entry from the grid, then press +the *[Delete]* button from the menu bar. + +**Tip**: Rather than deleting an entry, you can disable it instead by +pressing the *[Edit]* button, and unticking the "Enabled" check box. diff --git a/src/docs.c b/src/docs.c index c4b71f55e..684a9fad5 100644 --- a/src/docs.c +++ b/src/docs.c @@ -4,6 +4,7 @@ #define LANGPREF "\xff\x01" #define DOCINCPREF "\xff\x02" #define ITEMSINCPREF "\xff\x03" +#define MDINCLUDE "\xff\x04" #define N_(s) s #include "docs_inc.c" diff --git a/src/webui/doc_md.c b/src/webui/doc_md.c index 986b21fce..ae9a89bcc 100644 --- a/src/webui/doc_md.c +++ b/src/webui/doc_md.c @@ -22,6 +22,7 @@ #include "http.h" #include "docs.h" +static int md_doc(htsbuf_queue_t *hq, const char **doc, const char *lang, int nl); static int md_class(htsbuf_queue_t *hq, const char *clazz, const char *lang, int hdr, int docs, int props); @@ -164,6 +165,7 @@ md_props(htsbuf_queue_t *hq, htsmsg_t *m, const char *lang, int nl) static void md_render(htsbuf_queue_t *hq, const char *doc, const char *lang) { + const struct tvh_doc_page *page; if (doc[0] == '\xff') { switch (doc[1]) { case 1: @@ -175,6 +177,14 @@ md_render(htsbuf_queue_t *hq, const char *doc, const char *lang) case 3: md_class(hq, doc + 2, lang, 0, 0, 1); break; + case 4: + for (page = tvh_doc_markdown_pages; page->name; page++) + if (!strcmp(page->name, doc + 2)) { + if (page->strings) + md_doc(hq, page->strings, lang, 0); + break; + } + break; } } else { htsbuf_append_str(hq, doc); diff --git a/support/doc/md_to_c.py b/support/doc/md_to_c.py index 4ff36663f..664379e98 100755 --- a/support/doc/md_to_c.py +++ b/support/doc/md_to_c.py @@ -198,6 +198,8 @@ class TVH_C_Renderer(Renderer): if a: return a a = self.extra_cmd(text, 'tvh_class_items', 'i') if a: return a + a = self.extra_cmd(text, 'tvh_include', 'I') + if a: return a fatal('Block HTML not allowed: ' + repr(text)) def inline_html(self, text): @@ -384,15 +386,17 @@ def optimize(text): if x: r += lang(x) x = '' n += t - elif type == 'd' or type == 'i': + elif type in ['d', 'i', 'I']: if n: r += nolang(n) if x: r += lang(x) n = '' x = '' if type == 'd': r += 'DOCINCPREF "' + t + '",\n' - else: + elif type == 'i': r += 'ITEMSINCPREF "' + t + '",\n' + else: + r += 'MDINCLUDE "' + t + '",\n' text = text[p+l+1:] if x: r += lang(x) x = '' @@ -405,6 +409,18 @@ def optimize(text): # # +def dopages(pages): + print("\n\nconst struct tvh_doc_page tvh_doc_markdown_pages[] = {") + for page in pages.split(' '): + if not page: continue + print(" { \"%s\", tvh_doc_root_%s }," % (page, page.replace('/', '_'))) + print(" { NULL, NULL },") + print("};") + +# +# +# + def fatal(msg): sys.stderr.write('FATAL: ' + msg + '\n') sys.exit(1) @@ -426,12 +442,17 @@ def argv_get(what): HUMAN=argv_get('human') DEBUG=argv_get('debug') +pages = argv_get('pages') +if pages: + dopages(pages) + sys.exit(0) input = argv_get('in') if not input: fatal('Specify input file.') name = argv_get('name') if not name: fatal('Specify class name.') +name = name.replace('/', '_') fp = utf8open(input, 'r') text = fp.read(1024*1024*2)