Coverage for tests/test_simple_ln_hl.py: 100%

43 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2026-10-15 15:22 +0000

1import inspect 1ab

2 

3import markdown 1ab

4from inline_snapshot import snapshot 1ab

5from mdx_include.mdx_include import IncludeExtension 1ab

6from pymdownx.highlight import HighlightExtension 1ab

7from pymdownx.superfences import SuperFencesCodeExtension 1ab

8 

9from markdown_include_variants import IncludeVariantsExtension 1ab

10 

11 

12def test_simple_ln_hl(): 1ab

13 input_md = inspect.cleandoc( 1cd

14 """ 

15 {* docs_src/simple/tutorial001.py ln[1:4] hl[1:3] *} 

16 """ 

17 ) 

18 

19 result = markdown.markdown( 1cd

20 input_md, 

21 extensions=[ 

22 IncludeVariantsExtension(), 

23 ], 

24 ) 

25 assert result == snapshot( 1cd

26 inspect.cleandoc( 

27 """ 

28 <p>//// tab | Python 3.8+ 

29 ```python hl_lines="1-3" 

30 {!docs_src/simple/tutorial001.py[ln:1-4]!}</p> 

31 <h1>Code below omitted 👇</h1> 

32 <p>```</p> 

33 <p>////</p> 

34 <p>///// details | 👀 Full file preview</p> 

35 <p>//// tab | Python 3.8+</p> 

36 <p><code>python hl_lines="1-3" 

37 {!docs_src/simple/tutorial001.py!}</code></p> 

38 <p>////</p> 

39 <p>/////</p> 

40 """ 

41 ) 

42 ) 

43 

44 

45def test_simple_ln_hl_middle_block(): 1ab

46 input_md = inspect.cleandoc( 1ef

47 """ 

48 {* docs_src/simple/tutorial001.py ln[2:5] hl[2:3] *} 

49 """ 

50 ) 

51 

52 result = markdown.markdown( 1ef

53 input_md, 

54 extensions=[ 

55 IncludeVariantsExtension(), 

56 ], 

57 ) 

58 assert result == snapshot( 1ef

59 inspect.cleandoc( 

60 """ 

61 <p>//// tab | Python 3.8+ 

62 ```python hl_lines="3-4"</p> 

63 <h1>Code above omitted 👆</h1> 

64 <p>{!docs_src/simple/tutorial001.py[ln:2-5]!}</p> 

65 <h1>Code below omitted 👇</h1> 

66 <p>```</p> 

67 <p>////</p> 

68 <p>///// details | 👀 Full file preview</p> 

69 <p>//// tab | Python 3.8+</p> 

70 <p><code>python hl_lines="2-3" 

71 {!docs_src/simple/tutorial001.py!}</code></p> 

72 <p>////</p> 

73 <p>/////</p> 

74 """ 

75 ) 

76 ) 

77 

78 

79def test_simple_ln_hl_middle_block_end_block(): 1ab

80 input_md = inspect.cleandoc( 1gh

81 """ 

82 {* docs_src/simple/tutorial001.py ln[2:5, 8:10] hl[2:3,8:10] *} 

83 """ 

84 ) 

85 

86 result = markdown.markdown( 1gh

87 input_md, 

88 extensions=[ 

89 IncludeVariantsExtension(), 

90 ], 

91 ) 

92 assert result == snapshot( 1gh

93 inspect.cleandoc( 

94 """ 

95 <p>//// tab | Python 3.8+ 

96 ```python hl_lines="3-4 10-12"</p> 

97 <h1>Code above omitted 👆</h1> 

98 <p>{!docs_src/simple/tutorial001.py[ln:2-5]!}</p> 

99 <h1>Code here omitted 👈</h1> 

100 <p>{!docs_src/simple/tutorial001.py[ln:8-10]!} 

101 ```</p> 

102 <p>////</p> 

103 <p>///// details | 👀 Full file preview</p> 

104 <p>//// tab | Python 3.8+</p> 

105 <p><code>python hl_lines="2-3 8-10" 

106 {!docs_src/simple/tutorial001.py!}</code></p> 

107 <p>////</p> 

108 <p>/////</p> 

109 """ 

110 ) 

111 ) 

112 

113 

114def test_simple_ln_hl_middle_block_middle_block_end_block(): 1ab

115 input_md = inspect.cleandoc( 1ij

116 """ 

117 {* docs_src/simple/tutorial001.py ln[2:3,5:6,8:10] hl[2:3,5:6,8:10] *} 

118 """ 

119 ) 

120 

121 result = markdown.markdown( 1ij

122 input_md, 

123 extensions=[ 

124 IncludeVariantsExtension(), 

125 ], 

126 ) 

127 assert result == snapshot( 1ij

128 inspect.cleandoc( 

129 """ 

130 <p>//// tab | Python 3.8+ 

131 ```python hl_lines="3-4 8-9 13-15"</p> 

132 <h1>Code above omitted 👆</h1> 

133 <p>{!docs_src/simple/tutorial001.py[ln:2-3]!}</p> 

134 <h1>Code here omitted 👈</h1> 

135 <p>{!docs_src/simple/tutorial001.py[ln:5-6]!}</p> 

136 <h1>Code here omitted 👈</h1> 

137 <p>{!docs_src/simple/tutorial001.py[ln:8-10]!} 

138 ```</p> 

139 <p>////</p> 

140 <p>///// details | 👀 Full file preview</p> 

141 <p>//// tab | Python 3.8+</p> 

142 <p><code>python hl_lines="2-3 5-6 8-10" 

143 {!docs_src/simple/tutorial001.py!}</code></p> 

144 <p>////</p> 

145 <p>/////</p> 

146 """ 

147 ) 

148 ) 

149 

150 

151def test_simple_ln_hl_middle_middle_block_end(): 1ab

152 input_md = inspect.cleandoc( 1kl

153 """ 

154 {* docs_src/simple/tutorial001.py ln[2,5:6,10] hl[2,5:6,10] *} 

155 """ 

156 ) 

157 

158 result = markdown.markdown( 1kl

159 input_md, 

160 extensions=[ 

161 IncludeVariantsExtension(), 

162 ], 

163 ) 

164 assert result == snapshot( 1kl

165 inspect.cleandoc( 

166 """ 

167 <p>//// tab | Python 3.8+ 

168 ```python hl_lines="3 7-8 12"</p> 

169 <h1>Code above omitted 👆</h1> 

170 <p>{!docs_src/simple/tutorial001.py[ln:2-2]!}</p> 

171 <h1>Code here omitted 👈</h1> 

172 <p>{!docs_src/simple/tutorial001.py[ln:5-6]!}</p> 

173 <h1>Code here omitted 👈</h1> 

174 <p>{!docs_src/simple/tutorial001.py[ln:10-10]!} 

175 ```</p> 

176 <p>////</p> 

177 <p>///// details | 👀 Full file preview</p> 

178 <p>//// tab | Python 3.8+</p> 

179 <p><code>python hl_lines="2 5-6 10" 

180 {!docs_src/simple/tutorial001.py!}</code></p> 

181 <p>////</p> 

182 <p>/////</p> 

183 """ 

184 ) 

185 ) 

186 

187 

188def test_simple_ln_hl_first_middle_end(): 1ab

189 input_md = inspect.cleandoc( 1mn

190 """ 

191 {* docs_src/simple/tutorial001.py ln[1,6:8,10] hl[1,6:8,10] *} 

192 """ 

193 ) 

194 

195 result = markdown.markdown( 1mn

196 input_md, 

197 extensions=[ 

198 IncludeVariantsExtension(), 

199 ], 

200 ) 

201 assert result == snapshot( 1mn

202 inspect.cleandoc( 

203 """ 

204 <p>//// tab | Python 3.8+ 

205 ```python hl_lines="1 5-7 11" 

206 {!docs_src/simple/tutorial001.py[ln:1-1]!}</p> 

207 <h1>Code here omitted 👈</h1> 

208 <p>{!docs_src/simple/tutorial001.py[ln:6-8]!}</p> 

209 <h1>Code here omitted 👈</h1> 

210 <p>{!docs_src/simple/tutorial001.py[ln:10-10]!} 

211 ```</p> 

212 <p>////</p> 

213 <p>///// details | 👀 Full file preview</p> 

214 <p>//// tab | Python 3.8+</p> 

215 <p><code>python hl_lines="1 6-8 10" 

216 {!docs_src/simple/tutorial001.py!}</code></p> 

217 <p>////</p> 

218 <p>/////</p> 

219 """ 

220 ) 

221 ) 

222 

223 

224def test_simple_ln_hl_middle_block_end_block_hl_middle_block(): 1ab

225 input_md = inspect.cleandoc( 1op

226 """ 

227 {* docs_src/simple/tutorial001.py ln[2:3,8:10] hl[2] *} 

228 """ 

229 ) 

230 

231 result = markdown.markdown( 1op

232 input_md, 

233 extensions=[ 

234 IncludeVariantsExtension(), 

235 ], 

236 ) 

237 assert result == snapshot( 1op

238 inspect.cleandoc( 

239 """ 

240 <p>//// tab | Python 3.8+ 

241 ```python hl_lines="3"</p> 

242 <h1>Code above omitted 👆</h1> 

243 <p>{!docs_src/simple/tutorial001.py[ln:2-3]!}</p> 

244 <h1>Code here omitted 👈</h1> 

245 <p>{!docs_src/simple/tutorial001.py[ln:8-10]!} 

246 ```</p> 

247 <p>////</p> 

248 <p>///// details | 👀 Full file preview</p> 

249 <p>//// tab | Python 3.8+</p> 

250 <p><code>python hl_lines="2" 

251 {!docs_src/simple/tutorial001.py!}</code></p> 

252 <p>////</p> 

253 <p>/////</p> 

254 """ 

255 ) 

256 ) 

257 

258 

259def test_simple_ln_hl_middle_block_end_block_hl_end_block(): 1ab

260 input_md = inspect.cleandoc( 1qr

261 """ 

262 {* docs_src/simple/tutorial001.py ln[2:3,7:10] hl[8:9] *} 

263 """ 

264 ) 

265 

266 result = markdown.markdown( 1qr

267 input_md, 

268 extensions=[ 

269 IncludeVariantsExtension(), 

270 ], 

271 ) 

272 assert result == snapshot( 1qr

273 inspect.cleandoc( 

274 """ 

275 <p>//// tab | Python 3.8+ 

276 ```python hl_lines="9-10"</p> 

277 <h1>Code above omitted 👆</h1> 

278 <p>{!docs_src/simple/tutorial001.py[ln:2-3]!}</p> 

279 <h1>Code here omitted 👈</h1> 

280 <p>{!docs_src/simple/tutorial001.py[ln:7-10]!} 

281 ```</p> 

282 <p>////</p> 

283 <p>///// details | 👀 Full file preview</p> 

284 <p>//// tab | Python 3.8+</p> 

285 <p><code>python hl_lines="8-9" 

286 {!docs_src/simple/tutorial001.py!}</code></p> 

287 <p>////</p> 

288 <p>/////</p> 

289 """ 

290 ) 

291 ) 

292 

293 

294def test_simple_ln_hl_middle_block_end_block_hl_end_block_include(): 1ab

295 input_md = inspect.cleandoc( 1st

296 """ 

297 {* docs_src/simple/tutorial001.py ln[2:3,7:10] hl[8:9] *} 

298 """ 

299 ) 

300 

301 result = markdown.markdown( 1st

302 input_md, 

303 extensions=[ 

304 IncludeVariantsExtension(), 

305 IncludeExtension(), 

306 SuperFencesCodeExtension(), 

307 HighlightExtension(), 

308 ], 

309 ) 

310 assert result == snapshot( 1st

311 inspect.cleandoc( 

312 """ 

313 <p>//// tab | Python 3.8+ 

314 <div class="highlight"><pre><span></span><code><span class="c1"># Code above omitted 👆</span> 

315 

316 <span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 2"</span><span class="p">)</span> 

317 <span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 3"</span><span class="p">)</span> 

318 

319 <span class="c1"># Code here omitted 👈</span> 

320 

321 <span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 7"</span><span class="p">)</span> 

322 <span class="hll"><span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 8"</span><span class="p">)</span> 

323 </span><span class="hll"><span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 9"</span><span class="p">)</span> 

324 </span><span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 10"</span><span class="p">)</span> 

325 </code></pre></div></p> 

326 <p>////</p> 

327 <p>///// details | 👀 Full file preview</p> 

328 <p>//// tab | Python 3.8+</p> 

329 <div class="highlight"><pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 1"</span><span class="p">)</span> 

330 <span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 2"</span><span class="p">)</span> 

331 <span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 3"</span><span class="p">)</span> 

332 <span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 4"</span><span class="p">)</span> 

333 <span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 5"</span><span class="p">)</span> 

334 <span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 6"</span><span class="p">)</span> 

335 <span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 7"</span><span class="p">)</span> 

336 <span class="hll"><span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 8"</span><span class="p">)</span> 

337 </span><span class="hll"><span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 9"</span><span class="p">)</span> 

338 </span><span class="nb">print</span><span class="p">(</span><span class="s2">"simple line 10"</span><span class="p">)</span> 

339 </code></pre></div> 

340 <p>////</p> 

341 <p>/////</p> 

342 """ 

343 ) 

344 )