Skip to content

Commit e4486e1

Browse files
committed
feat: enhance article layout and styling; add word break and overflow handling for code elements; implement H3 header component in rehype plugin; adjust layout styles for better responsiveness
1 parent 1039ab1 commit e4486e1

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/lib/assets/mdlayouts/article.svelte

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
1010
:global(.container-wrapper a) {
1111
color: var(--link-text);
12+
1213
}
14+
15+
:global(.container-wrapper * code) {
16+
word-break: break-word;
17+
overflow-wrap: break-word; /* Breaks words only if they don't fit */
18+
white-space: pre-line; /* Preserves whitespace and wraps lines */
19+
}
1320
:global(.container-wrapper) {
1421
visibility: visible;
1522
@@ -35,6 +42,9 @@
3542
width: calc(100vw - 175px);
3643
overflow-wrap: break-word;
3744
word-break: break-word;
45+
46+
47+
3848
}
3949
:global(.outer-wrapper) {
4050
width: 100%;
@@ -105,4 +115,15 @@
105115
transform: skewX(50deg);
106116
}
107117
118+
:global(.h3-wrapper)
119+
{
120+
color: rgba(0, 0, 0, 1);
121+
padding: 0;
122+
font-size: 1.5rem;
123+
margin: auto;
124+
margin-left: 2%;
125+
text-align: left;
126+
vertical-align: middle;
127+
}
128+
108129
</style>

src/lib/plugins/rehype-section-wrapper.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,30 @@ export default function rehypeSectionWrapper() {
6565
currentWrapper = null;
6666
continue;
6767
}
68+
69+
if (node.type === 'element' && node.tagName === 'h3') {
70+
// 1. Extract the text content of the H3.
71+
const headerText = toString(node);
72+
73+
// 2. Create a new <Header> component element with a 'title' prop.
74+
const headerComponent = h('div.outer-wrapper', [h('h3.h3-wrapper', headerText), h('div.middle-wrapper',
75+
[h('div.inter-wrapper', [])])]);
76+
77+
if (currentWrapper) {
78+
if (currentWrapper.children.length === 1) {
79+
// If the current wrapper is empty, remove it
80+
newChildren.pop();
81+
}
82+
}
83+
// 3. Add the new <Header> component to the wrapper.
84+
newChildren.push(h('br', [])); // Add a horizontal rule before the header
85+
newChildren.push(headerComponent);
86+
newChildren.push(h('br', []));
87+
currentWrapper = null;
88+
continue;
89+
}
90+
91+
6892
if (node.type === 'element' && node.tagName === 'hr') {
6993
newChildren.push(h('br', [])); // Add a horizontal rule before the header
7094
currentWrapper = null;

src/routes/posts/mdarticles/[slug]/+layout.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
main {
1212
position: relative;
1313
margin: 0;
14-
min-width: 100vw;
14+
15+
max-width: 100vw;
1516
min-height: 100vh;
1617
1718
color: black;
@@ -22,5 +23,7 @@ main {
2223
background-attachment: fixed;
2324
2425
background-position: center;
26+
27+
overflow-x: clip;
2528
}
2629
</style>

0 commit comments

Comments
 (0)