Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mdhelp: add <tvh_include> support for markdown
  • Loading branch information
perexg committed May 5, 2016
1 parent 06fdb8b commit c92eeb5
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 37 deletions.
9 changes: 3 additions & 6 deletions Makefile
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
33 changes: 4 additions & 29 deletions docs/class/ipblocking.md
Expand Up @@ -5,45 +5,20 @@ 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.
<tvh_include>inc/buttons1</tvh_include>

---

###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.
<tvh_include>inc/add1</tvh_include>

!['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
[this guide](https://www.ripe.net/about-us/press-centre/understanding-ip-addressing).

---

### 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.
<tvh_include>inc/del1</tvh_include>

---
8 changes: 8 additions & 0 deletions 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.
13 changes: 13 additions & 0 deletions 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.
7 changes: 7 additions & 0 deletions 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.
1 change: 1 addition & 0 deletions src/docs.c
Expand Up @@ -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"
10 changes: 10 additions & 0 deletions src/webui/doc_md.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand Down
25 changes: 23 additions & 2 deletions support/doc/md_to_c.py
Expand Up @@ -198,6 +198,8 @@ def block_html(self, text):
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):
Expand Down Expand Up @@ -384,15 +386,17 @@ def lang(t):
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 = ''
Expand All @@ -405,6 +409,18 @@ def lang(t):
#
#

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)
Expand All @@ -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)
Expand Down

0 comments on commit c92eeb5

Please sign in to comment.