|
104 | 104 |
|
105 | 105 | <!-- Add header for code snippets --> |
106 | 106 |
|
107 | | -{% if _content contains '<div class="language-' %} |
108 | | - {% assign _code_splits = _content | split: '<div class="language-' %} |
109 | | - {% assign _new_content = nil %} |
| 107 | +{% if _content contains '<div class="highlight"><code>' %} |
| 108 | + {% assign _code_spippets = _content | split: '<div class="highlight"><code>' %} |
| 109 | + {% assign _new_content = '' %} |
| 110 | + |
| 111 | + {% for _snippet in _code_spippets %} |
| 112 | + |
| 113 | + {% if forloop.last %} |
| 114 | + {% assign _new_content = _new_content | append: _snippet %} |
110 | 115 |
|
111 | | - {% for _snippet in _code_splits %} |
112 | | - {% if forloop.first %} |
113 | | - {% assign _new_content = _snippet %} |
114 | 116 | {% else %} |
115 | | - {% assign _lang = _snippet | split: ' ' | first %} |
116 | | - {% capture _tag_head %}<div class="language-{% endcapture %} |
117 | | - {% assign _replacement = '-rouge"><div class="code-header" data-lang="' |
118 | | - | append: _lang |
| 117 | + |
| 118 | + {% assign _left = _snippet | split: '><' | last%} |
| 119 | + |
| 120 | + {% if _left contains 'file="' %} |
| 121 | + {% assign _text = _left | split: 'file="' | last | split: '"' | first %} |
| 122 | + {% else %} |
| 123 | + {% assign _text = _left | split: 'language-' | last | split: ' ' | first %} |
| 124 | + {% endif %} |
| 125 | + |
| 126 | + {% assign _new_content = _new_content | append: _snippet |
| 127 | + | append: '<div class="code-header" text-data="' |
| 128 | + | append: _text |
119 | 129 | | append: '"><button data-original-title="' |
120 | 130 | | append: site.data.locales[lang].post.button.copy |
121 | | - | append: '"><i class="far fa-clone"></i></button></div><div class="highlight">' |
| 131 | + | append: '"><i class="far fa-clone"></i></button></div>' |
| 132 | + | append: '<div class="highlight"><code>' |
122 | 133 | %} |
123 | | - {% capture _tag_tail %}{{ _snippet | replace: '-rouge"><div class="highlight">', _replacement }}{% endcapture %} |
124 | | - {% assign _new_content = _new_content | append: _tag_head | append: _tag_tail %} |
| 134 | + |
125 | 135 | {% endif %} |
| 136 | + |
126 | 137 | {% endfor %} |
127 | 138 |
|
128 | | - {% if _new_content %} |
129 | | - {% assign _content = _new_content %} |
130 | | - {% endif %} |
| 139 | + {% assign _content = _new_content %} |
131 | 140 |
|
132 | 141 | {% endif %} |
133 | 142 |
|
|
0 commit comments