Skip to content

Commit 2b3bdf1

Browse files
committed
Auto merge of #3220 - Turbo87:readme, r=locks
Extract `RenderedHtml` component This PR extracts a new `RenderedHtml` component, which is used to render the README content on the crate details pages. To make the component easier to handle and align on the page, the styling was slightly adjusted so that the component does not have any outer margin by default. r? `@locks`
2 parents 30ce0b4 + d79e539 commit 2b3bdf1

File tree

4 files changed

+51
-32
lines changed

4 files changed

+51
-32
lines changed

app/components/rendered-html.hbs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{!--
2+
This component renders raw HTML. Be very careful with this since it
3+
can enable cross-site scripting attacks!
4+
--}}
5+
<div local-class="wrapper" ...attributes {{highlight-syntax selector="pre > code"}}>
6+
{{html-safe @html}}
7+
</div>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.wrapper {
2+
line-height: 1.5;
3+
overflow-wrap: break-word;
4+
5+
> :first-child {
6+
margin-top: 0;
7+
}
8+
9+
> :last-child {
10+
margin-bottom: 0;
11+
}
12+
13+
img {
14+
max-width: 100%;
15+
}
16+
17+
pre {
18+
overflow-x: auto;
19+
}
20+
21+
p {
22+
code {
23+
background-color: #fff;
24+
padding: 0 2px;
25+
}
26+
}
27+
28+
table {
29+
border-collapse: collapse;
30+
display: block;
31+
overflow-x: auto;
32+
33+
th, td {
34+
border: 1px solid #dfe2e5;
35+
padding: 6px 13px;
36+
}
37+
}
38+
}

app/styles/crate/version.module.css

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ div.header {
6666
.docs {
6767
@media only screen and (min-width: 890px) {
6868
flex: 7;
69-
padding-right: 40px;
69+
padding-right: 20px;
7070
max-width: 640px;
7171
}
7272
}
@@ -194,35 +194,9 @@ div.header {
194194
margin-bottom: 40px;
195195
}
196196

197-
.crate-readme {
198-
line-height: 1.5;
199-
overflow-wrap: break-word;
200-
201-
img {
202-
max-width: 100%;
203-
}
204-
205-
pre {
206-
overflow-x: auto;
207-
}
208-
209-
p {
210-
code {
211-
background-color: #fff;
212-
padding: 0 2px;
213-
}
214-
}
215-
216-
table {
217-
border-collapse: collapse;
218-
display: block;
219-
overflow-x: auto;
220-
221-
th, td {
222-
border: 1px solid #dfe2e5;
223-
padding: 6px 13px;
224-
}
225-
}
197+
.readme {
198+
margin-top: 20px;
199+
margin-bottom: 20px;
226200
}
227201

228202
.crate-downloads {

app/templates/crate/version.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
{{/if}}
6767
</div>
6868
{{#if this.readme}}
69-
<section local-class="crate-readme" aria-label="Readme" {{highlight-syntax selector="pre > code"}}>
70-
{{html-safe this.readme}}
69+
<section aria-label="Readme">
70+
<RenderedHtml @html={{this.readme}} local-class="readme" />
7171
</section>
7272
{{else}}
7373
{{#if this.crate.description}}

0 commit comments

Comments
 (0)