File tree Expand file tree Collapse file tree
kotlin/com/linuxcommandlibrary/desktop Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,27 @@ object HtmlMarkdownRenderer {
2323 }
2424 }
2525
26+ /* *
27+ * Render sections with multi-line code blocks styled as previews (monospace, no $ prefix, no copy button).
28+ */
29+ fun renderSectionsWithPreviews (sections : List <TipSectionElement >): String = buildString {
30+ sections.forEach { section ->
31+ when (section) {
32+ is TipSectionElement .Text -> append(renderText(section))
33+ is TipSectionElement .Blockquote -> append(renderBlockquote(section))
34+ is TipSectionElement .Code -> {
35+ val isMultiLine = section.command.contains(" \n " )
36+ if (isMultiLine) {
37+ append(renderPreviewCode(section))
38+ } else {
39+ append(renderCode(section))
40+ }
41+ }
42+ is TipSectionElement .Table -> append(renderTable(section))
43+ }
44+ }
45+ }
46+
2647 private fun renderText (text : TipSectionElement .Text ): String = buildString {
2748 append(" <span>" )
2849 text.elements.forEach { element ->
@@ -78,6 +99,18 @@ object HtmlMarkdownRenderer {
7899 }
79100 }
80101
102+ private fun renderPreviewCode (code : TipSectionElement .Code ): String = buildString {
103+ append(""" <pre class="code-preview">""" )
104+ code.elements.forEach { element ->
105+ when (element) {
106+ is CommandElement .Text -> append(element.text.escapeHtml())
107+ is CommandElement .Man -> append(element.man.escapeHtml())
108+ is CommandElement .Url -> append(element.command.escapeHtml())
109+ }
110+ }
111+ append(" </pre>" )
112+ }
113+
81114 private fun renderTable (table : TipSectionElement .Table ): String = buildString {
82115 append(" <table>" )
83116
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ class WebsiteBuilder(
119119 private val pastSponsors : List <Pair <String , String >> = emptyList(),
120120) {
121121
122- private val cacheVersion = 14
122+ private val cacheVersion = 15
123123
124124 /* *
125125 * Get sorted list of command names from markdown files.
@@ -442,7 +442,11 @@ class WebsiteBuilder(
442442 }
443443 }
444444 unsafe {
445- + HtmlMarkdownRenderer .renderSections(group.sections)
445+ if (categoryTitle == " Terminal games" ) {
446+ + HtmlMarkdownRenderer .renderSectionsWithPreviews(group.sections)
447+ } else {
448+ + HtmlMarkdownRenderer .renderSections(group.sections)
449+ }
446450 }
447451 }
448452 }
@@ -716,6 +720,14 @@ class WebsiteBuilder(
716720 }
717721 }
718722
723+ " PREVIEW" -> {
724+ div {
725+ unsafe {
726+ + HtmlMarkdownRenderer .renderSectionsWithPreviews(section.elements)
727+ }
728+ }
729+ }
730+
719731 else -> {
720732 // Use HtmlMarkdownRenderer for all other sections
721733 p {
@@ -1275,9 +1287,9 @@ class WebsiteBuilder(
12751287 id = " app-link"
12761288 href = " https://github.com/SimonSchubert/Kai"
12771289 img {
1290+ style= " max-width: 100%;"
12781291 src = " /images/af/kai-1-horizontal.webp"
12791292 alt = " Kai"
1280- height = " 160"
12811293 }
12821294 }
12831295 script {
Original file line number Diff line number Diff line change @@ -494,6 +494,17 @@ pre {
494494 margin-bottom : auto;
495495}
496496
497+ .code-preview {
498+ color : # fff ;
499+ background-color : # 000 ;
500+ padding : 8px ;
501+ font-family : 'Courier New' , Courier, monospace;
502+ white-space : pre;
503+ width : fit-content;
504+ margin : 4px 0 8px 0 ;
505+ line-height : 1.2 ;
506+ }
507+
497508.visible {
498509 visibility : visible !important ;
499510 opacity : 1 ;
You can’t perform that action at this time.
0 commit comments