added full conditional comments...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-08-20 00:56:37 +03:00
parent 8937ae5e86
commit ca5fcf8801
4 changed files with 43 additions and 6 deletions

View File

@ -13,7 +13,7 @@ are likely to change, the implementation / API **will definitely** change! ;)_
without requiring setting up and maintaining a write-convert-embed without requiring setting up and maintaining a write-convert-embed
workflow. workflow.
This was a requirement on the _ImageGrid.Viewer_ project and as a This was a requirement on the _\ImageGrid.Viewer_ project and as a
side-effect pWiki hosts it's own documentation too. side-effect pWiki hosts it's own documentation too.
- _Pluggable storage and synchronization_ mechanisms - _Pluggable storage and synchronization_ mechanisms

2
bootstrap.js vendored

File diff suppressed because one or more lines are too long

View File

@ -60,6 +60,29 @@ are escaped a bit differently:
### Conditional comments
In addition to HTML and filter-specific comments pWiki provides two types
of conditional comments that serve two specific functions:
Show something in pWiki but hide it in HTML:
```
<!--\[pWiki[ ... ]]-->
```
Show something in HTML but hide in pWiki:
<pre>
&lt;pwiki-comment&gt; ... &lt;/pwiki-comment&gt;
or
\@pwiki-comment( ... )
</pre>
This will enable writing documents (mainly in _markdown_) that are usable
bot from within pWiki as well as outside.
## Macros ## Macros
@ -139,9 +162,10 @@ Arguments:
**Example:** **Example:**
[Templates/\_css] / [bootstrap css](bootstrap/Templates/_css.html): [Templates/\_css] / [bootstrap css](bootstrap/Templates/_css.html):
``` <!--[pWiki[```
@source(Templates/_css) @source(Templates/_css)
``` ```
]]-->
### slot (name text) ### slot (name text)

19
wiki.js
View File

@ -48,6 +48,11 @@ var setWikiWords = function(text, show_brackets, skip){
.replace( .replace(
Wiki.__wiki_link__, Wiki.__wiki_link__,
function(l){ function(l){
// check if wikiword is escaped...
if(l[0] == '\\'){
return l.slice(1)
}
var path = l[0] == '[' ? l.slice(1, -1) : l var path = l[0] == '[' ? l.slice(1, -1) : l
var i = [].slice.call(arguments).slice(-2)[0] var i = [].slice.call(arguments).slice(-2)[0]
@ -125,7 +130,9 @@ var macro = {
macro: { macro: {
"pwiki-comment": Macro('hide in pWiki', "pwiki-comment": Macro('hide in pWiki',
[], [],
function(context, elem, state){ return '' }), function(context, elem, state){
return ''
}),
now: Macro('Create a now id', now: Macro('Create a now id',
[], [],
function(context, elem, state){ return ''+Date.now() }), function(context, elem, state){ return ''+Date.now() }),
@ -570,6 +577,12 @@ var macro = {
// get actual element content... // get actual element content...
var text = $('<div>').append($(e).clone()).html() var text = $('<div>').append($(e).clone()).html()
// conditional comment...
if(e.nodeType == e.COMMENT_NODE
&& /^<!--\[pWiki\[(.|\n)*\]\]-->$/.test(text)){
text = text.slice(11, -5)
}
$(e).replaceWith(_parseText(context, text, macro)) $(e).replaceWith(_parseText(context, text, macro))
// node -> html-style + attrs... // node -> html-style + attrs...
@ -1008,8 +1021,8 @@ var Wiki = {
//__redirect_template__: 'RedirectTemplate', //__redirect_template__: 'RedirectTemplate',
__wiki_link__: RegExp('('+[ __wiki_link__: RegExp('('+[
'(\\./|\\.\\./|[A-Z][a-z0-9]+[A-Z/])[a-zA-Z0-9/]*', '\\\\?(\\./|\\.\\./|[A-Z][a-z0-9]+[A-Z/])[a-zA-Z0-9/]*',
'\\[[^\\]]+\\]', '\\\\?\\[[^\\]]+\\]',
].join('|') +')', 'g'), ].join('|') +')', 'g'),
__macro_parser__: macro, __macro_parser__: macro,