<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.undertensai.cn/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E6%9D%BF%3ACodeCommentary%2Fdoc</id>
	<title>模板:CodeCommentary/doc - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.undertensai.cn/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E6%9D%BF%3ACodeCommentary%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://wiki.undertensai.cn/index.php?title=%E6%A8%A1%E6%9D%BF:CodeCommentary/doc&amp;action=history"/>
	<updated>2026-11-17T02:06:18Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.undertensai.cn/index.php?title=%E6%A8%A1%E6%9D%BF:CodeCommentary/doc&amp;diff=23769&amp;oldid=prev</id>
		<title>wiki&gt;ArielGlenn：​record odd behavior of pre-blocks in edit preview window</title>
		<link rel="alternate" type="text/html" href="https://wiki.undertensai.cn/index.php?title=%E6%A8%A1%E6%9D%BF:CodeCommentary/doc&amp;diff=23769&amp;oldid=prev"/>
		<updated>2020-12-14T18:45:20Z</updated>

		<summary type="html">&lt;p&gt;record odd behavior of pre-blocks in edit preview window&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Documentation subpage}}&lt;br /&gt;
== Usage ==&lt;br /&gt;
Use the template to display blocks of code with syntax highlighting interspersed with blocks of commentary.&lt;br /&gt;
&lt;br /&gt;
Additionally, you can add an icon next to a specific line of the code block, of an eye (indicating &amp;quot;look here!&amp;quot;) or of a pointing hand (this may take a link; since we cannot directly add a link a class name in a code block, this is the next best thing.&lt;br /&gt;
&lt;br /&gt;
And finally, you can add a block of not-quite-code with pre-style formatting (no line numbers, monospace font, etc) with an optional arrow icon next to a line.&lt;br /&gt;
&lt;br /&gt;
To add a commentary block, do the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{{CodeCommentary|type=comment|content=&lt;br /&gt;
Here goes all my lovely lovely commentary.&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To add a code block with no icon, do the following (using the language of your choice from [[Extension:SyntaxHighlight#Supported_languages|this list]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{{CodeCommentary|type=code|lang=python|content=&lt;br /&gt;
#!/usr/bin/python3 ...&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To add a code block with an eyes icon at line 3 in the block (counting from 1 always), do:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{{CodeCommentary|type=code|lang=python|icon=eyes|pos=3|content=&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
&lt;br /&gt;
import this&lt;br /&gt;
import that&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To add a code bloc with a hand icon at line 3 in the block and a link, do:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{{CodeCommentary|type=code|lang=python|icon=hand|pos=3|link=https://www.pylint.org/|content=&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
&lt;br /&gt;
import this&lt;br /&gt;
import that&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may also change the line numbering to start with a different number, if you are spltting up a longer piece of code into blocks for commentary, as intended with this template. TO start a code block with line 5, do:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{{CodeCommentary|type=code|lang=python|start=5|content=&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
&lt;br /&gt;
import this&lt;br /&gt;
import that&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To add a block of ...stuff... with pre-style formatting and an arrow icon, use&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{{CodeCommentary|type=pre|icon=arrow|pos=2|content=&lt;br /&gt;
1 max continue none /bin/bash ./worker --skipdone --exclusive --log --configfile /etc/dumps/confs/wikidump.conf.dumps --date {STARTDATE} --onepass --prereqs --skipjobs metahistorybz2dump,metahistorybz2dumprecombine,metahistory7zdump,metahistory7zdumprecombine,xmlflowhistorydump&lt;br /&gt;
6 max continue none /bin/bash ./worker --skipdone --exclusive --log --configfile /etc/dumps/confs&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Warnings ==&lt;br /&gt;
&lt;br /&gt;
The syntax highlighter, or maybe it&amp;#039;s MediaWiki, will toss leading blanks on the first and last lines of content of your code blocks. Stop this&lt;br /&gt;
from happening by putting a zero-width-space (&amp;amp;amp;#8203;) as the first character of such a line.&lt;br /&gt;
&lt;br /&gt;
You can use the template [[Template:ZWS]] to add one at the beginning of such lines.&lt;br /&gt;
&lt;br /&gt;
You may also need to use [[Template:(]] to replace left curly brackets in some circumstances,&lt;br /&gt;
or [[Template:))]] to replace double right curly brackets.&lt;br /&gt;
&lt;br /&gt;
Pre-blocks next to commentary blocks may be displayed with extra white space between them during an edit preview.&lt;br /&gt;
After save they should look fine.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
Do:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{{CodeCommentary|type=comment|content=&lt;br /&gt;
Here is a wee bit of text because, meh, we need it for an example&lt;br /&gt;
&lt;br /&gt;
A bit more text because that&amp;#039;s how we roll.&lt;br /&gt;
&lt;br /&gt;
Ok done now.&lt;br /&gt;
}}&lt;br /&gt;
{{CodeCommentary|type=code|start=1|lang=python|icon=hand|pos=3|link=User:ArielGlenn|content=&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
from subprocess import PIPE&lt;br /&gt;
&lt;br /&gt;
# just a few line of crap to illustrate the point&lt;br /&gt;
}}&lt;br /&gt;
{{CodeCommentary|type=pre|icon=arrow|pos=2|content=&lt;br /&gt;
dblist=/srv/mediawiki/dblists/all.dblist&lt;br /&gt;
privatelist=/srv/mediawiki/dblists/private.dblist&lt;br /&gt;
closedlist=/srv/mediawiki/dblists/closed.dblist&lt;br /&gt;
skipdblist=/etc/dumps/dblists/skip.dblist&lt;br /&gt;
flowlist=/srv/mediawiki/dblists/flow.dblist&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to get &lt;br /&gt;
&lt;br /&gt;
{{CodeCommentary|type=comment|content=&lt;br /&gt;
Here is a wee bit of text because, meh, we need it for an example&lt;br /&gt;
&lt;br /&gt;
A bit more text because that&amp;#039;s how we roll.&lt;br /&gt;
&lt;br /&gt;
Ok done now.&lt;br /&gt;
}}&lt;br /&gt;
{{CodeCommentary|type=code|start=1|lang=python|icon=hand|pos=3|link=User:ArielGlenn|content=&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
from subprocess import PIPE&lt;br /&gt;
&lt;br /&gt;
# just a few line of crap to illustrate the point&lt;br /&gt;
}}&lt;br /&gt;
{{CodeCommentary|type=pre|icon=arrow|pos=2|content=&lt;br /&gt;
dblist=/srv/mediawiki/dblists/all.dblist&lt;br /&gt;
privatelist=/srv/mediawiki/dblists/private.dblist&lt;br /&gt;
closedlist=/srv/mediawiki/dblists/closed.dblist&lt;br /&gt;
skipdblist=/etc/dumps/dblists/skip.dblist&lt;br /&gt;
flowlist=/srv/mediawiki/dblists/flow.dblist&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;templatedata&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
	&amp;quot;params&amp;quot;: {&lt;br /&gt;
		&amp;quot;type&amp;quot;: {&lt;br /&gt;
			&amp;quot;label&amp;quot;: &amp;quot;Block type&amp;quot;,&lt;br /&gt;
			&amp;quot;description&amp;quot;: &amp;quot;\&amp;quot;code\&amp;quot; for a code block, \&amp;quot;commentary\&amp;quot; for a commentary block, \&amp;quot;pre\&amp;quot; for an unnumbered pre-style block&amp;quot;,&lt;br /&gt;
			&amp;quot;type&amp;quot;: &amp;quot;string&amp;quot;,&lt;br /&gt;
			&amp;quot;default&amp;quot;: &amp;quot;code&amp;quot;&lt;br /&gt;
		},&lt;br /&gt;
		&amp;quot;content&amp;quot;: {&lt;br /&gt;
			&amp;quot;label&amp;quot;: &amp;quot;Block content&amp;quot;,&lt;br /&gt;
			&amp;quot;description&amp;quot;: &amp;quot;Content of a code commentary block, or code in the case of a code block&amp;quot;,&lt;br /&gt;
			&amp;quot;example&amp;quot;: &amp;quot;Here is some code commentary.&amp;quot;,&lt;br /&gt;
			&amp;quot;type&amp;quot;: &amp;quot;content&amp;quot;&lt;br /&gt;
		},&lt;br /&gt;
		&amp;quot;pos&amp;quot;: {&lt;br /&gt;
			&amp;quot;label&amp;quot;: &amp;quot;Icon position&amp;quot;,&lt;br /&gt;
			&amp;quot;description&amp;quot;: &amp;quot;If an icon is specified, place that icon next to this line in the code block&amp;quot;,&lt;br /&gt;
			&amp;quot;example&amp;quot;: &amp;quot;3&amp;quot;,&lt;br /&gt;
			&amp;quot;type&amp;quot;: &amp;quot;number&amp;quot;&lt;br /&gt;
		},&lt;br /&gt;
		&amp;quot;icon&amp;quot;: {&lt;br /&gt;
			&amp;quot;label&amp;quot;: &amp;quot;Icon&amp;quot;,&lt;br /&gt;
			&amp;quot;description&amp;quot;: &amp;quot;In a code block, \&amp;quot;eyes\&amp;quot; {eye icon) or \&amp;quot;hand\&amp;quot; (hand icon), in a pre block, \&amp;quot;arrow\&amp;quot; (arrow icon)&amp;quot;,&lt;br /&gt;
			&amp;quot;example&amp;quot;: &amp;quot;eyes&amp;quot;,&lt;br /&gt;
			&amp;quot;type&amp;quot;: &amp;quot;string&amp;quot;&lt;br /&gt;
		},&lt;br /&gt;
		&amp;quot;link&amp;quot;: {&lt;br /&gt;
			&amp;quot;label&amp;quot;: &amp;quot;Hand link target&amp;quot;,&lt;br /&gt;
			&amp;quot;description&amp;quot;: &amp;quot;In a code block, if \&amp;quot;hand\&amp;quot; is specified, it can be given a link target via this parameter.&amp;quot;,&lt;br /&gt;
			&amp;quot;example&amp;quot;: &amp;quot;https://www.mediawiki.org&amp;quot;,&lt;br /&gt;
			&amp;quot;type&amp;quot;: &amp;quot;url&amp;quot;&lt;br /&gt;
		},&lt;br /&gt;
		&amp;quot;lang&amp;quot;: {&lt;br /&gt;
			&amp;quot;label&amp;quot;: &amp;quot;Block code language&amp;quot;,&lt;br /&gt;
			&amp;quot;description&amp;quot;: &amp;quot;One of the languages known to the SyntaxHighlight extension&amp;quot;,&lt;br /&gt;
			&amp;quot;example&amp;quot;: &amp;quot;python&amp;quot;,&lt;br /&gt;
			&amp;quot;type&amp;quot;: &amp;quot;string&amp;quot;&lt;br /&gt;
		},&lt;br /&gt;
		&amp;quot;start&amp;quot;: {&lt;br /&gt;
			&amp;quot;label&amp;quot;: &amp;quot;Start number of code block&amp;quot;,&lt;br /&gt;
			&amp;quot;description&amp;quot;: &amp;quot;For code blocks, number the lines in this block starting from this number&amp;quot;,&lt;br /&gt;
			&amp;quot;example&amp;quot;: &amp;quot;5&amp;quot;,&lt;br /&gt;
			&amp;quot;type&amp;quot;: &amp;quot;number&amp;quot;&lt;br /&gt;
		}&lt;br /&gt;
	},&lt;br /&gt;
	&amp;quot;description&amp;quot;: &amp;quot;Display code blocks interspersed with blocks of commentary.&amp;quot;,&lt;br /&gt;
	&amp;quot;format&amp;quot;: &amp;quot;block&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/templatedata&amp;gt;&lt;/div&gt;</summary>
		<author><name>wiki&gt;ArielGlenn</name></author>
	</entry>
</feed>