Attached is an interesting solution to transclude codes from a tiddler.
This is useful when you want to discuss part of the code.

1. The code has a macro and a stylesheet
2. It is possible to transclude any part of code (say from line n to line
m)
4. Macro accepts ALSO a composite range like "2-5, 7 9, 13-18" and *stands
out* those lines no matter in what order you pass the selected range
5. The stand out lines have different background and high contrast while
other parts of the code are a little faded out
6. To give a try
6.1. Download attached JSON
6.2. Drag and drop to https://tiddlywiki.com/prerelease/
6.3. Open highlight-selected-lines/test01

I would like to get feedback and tell me how the efficiency can be
improved.

Best wishes
Mohammad

The macro and its sub macro is given below ( highlight-selected-lines/macro)

\define hslines(tid, from, to, rng, language)<$wikify name="numbers"
text=<<rawlist>> ><$vars length={{{ [[$to$]subtract[$from$]add[1]] }}}
><$set name="lines" filter="[[$tid$]get[text]splitregexp[\n]addsuffix[
]first[$to$]last<length>]"><ol start="$from$" class="code-list"><$list
filter="[range[$from$,$to$,1]]" variable=num><$list
filter="[enlist<numbers>nsort[]match<num>then[code-selected]else[code-notselected]]"
variable=selectedClass><$vars pos={{{ [<num>subtract[$from$]add[1]]
}}} ><span class=<<selectedClass>> ><li><$codeblock code={{{
[enlist:raw<lines>nth<pos>]  }}} language=<<__language__>>/></li>
</span></$vars></$list></$list></ol></$set></$vars></$wikify>
\end

\define rng2list() {{{[range[$(start)$,$(end)$]addsuffix[ ]]}}}

\define rawlist()<$list filter="[<__rng__>split[,]split[ ]!is[blank]]"
variable=num><$list filter="[<num>search:title[-]]"
emptyMessage=<<num>> variable=vrng><$vars start= {{{
[<vrng>split[-]first[]] }}}
       end=   {{{ [<vrng>split[-]last[]] }}} >
             <<rng2list>></$vars>                        </$list></$list>
\end

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/CAAV1gMAaxTcjsKEB-mKE1rZGk1-e2%2BXFfUTsxkBfMRsR-12P8g%40mail.gmail.com.

Attachment: standout-lines-of-code.json
Description: application/json

Reply via email to