From d332fc3fd40e4ef81f381129b433a074343779ed Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 19 Jan 2017 00:52:46 -0800 Subject: [PATCH] Markdown.pl: tweak code block output again Originally code blocks simply output this:
the code block text>
However that sometimes led to unsatisfying formatting with some browsers (especially text ones) and so that was ultimately changed to this:
code block text
The div then additionally has a class to facilitate formatting with a style sheet. The empty
causes agents that would otherwise make a poor formatting choice to do "the right thing"(tm) instead. However, the "
" kludge is unsatisfying for a number of reasons. Instead output this:
code block text
where the first div still has a class to facilitate formatting via a style sheet, but the replacement "
" block has an
embedded style and is actually emitted like so:

  


While this is still a kludge, it's much more satisfying because:

1. The same element type is being used to force those recalictrant
   text agents to do "the right thing"(tm).

2. The explict style="display:none" attribute completely protects
   properly behaving agents from any unwanted side-effects from
   the extra "
" tag pair.

Together with this change, the --stub stylesheet has also been
modified to use a more universally (i.e. page background is not
white) compatible styling for the code blocks themselves.

Signed-off-by: Kyle J. McKay 
---
 Markdown.pl | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/Markdown.pl b/Markdown.pl
index cef11c7..73cbc8a 100755
--- a/Markdown.pl
+++ b/Markdown.pl
@@ -493,7 +493,7 @@ sub _HashBTCodeBlocks {
 	    $codeblock =~ s/\A\n+//; # trim leading newlines
 	    $codeblock =~ s/\s+\z//; # trim trailing whitespace
 	    $codeblock = _EncodeCode($codeblock); # or run highlighter here
-	    $codeblock = "
"
+	    $codeblock = "
"
 		. $codeblock . "\n
"; my $key = block_id($codeblock); @@ -1574,7 +1574,7 @@ sub _DoCodeBlocks { $codeblock =~ s/\A\n+//; # trim leading newlines $codeblock =~ s/\s+\z//; # trim trailing whitespace - my $result = "
"
+	    my $result = "
"
 		. $codeblock . "\n
"; my $key = block_id($result); $g_code_blocks{$key} = $result; @@ -1990,12 +1990,19 @@ BEGIN { */ div.%(base)code-bt > pre, div.%(base)code > pre { - margin: 0 3ex; - padding: 1ex; - background-color: #eee; + margin: 0; + padding: 0; overflow: auto; } +div.%(base)code-bt > pre > code, div.%(base)code > pre > code { + display: inline-block; + margin: 0; + padding: 0.5em 0; + border-top: thin dotted; + border-bottom: thin dotted; +} + ol.%(base)ol { counter-reset: %(base)item; } @@ -2322,7 +2329,7 @@ Z<> See the F file for detailed release notes for this version. =item Copyright (C) 2003-2004 John Gruber -=item Copyright (C) 2015,2016 Kyle J. McKay +=item Copyright (C) 2015-2017 Kyle J. McKay =item All rights reserved.