Skip to content

Commit a5877c0

Browse files
committed
fix(markdown): render markdown string with proper design
1 parent 32d2b1b commit a5877c0

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

src/components/AgendaList/AgendaListItemDetail.vue

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
<div class="g-agenda-list-item-detail-title">
1414
{{ session.zh.title }}
1515
</div>
16-
<div class="g-agenda-list-item-detail-description">
17-
{{ session.zh.description }}
18-
</div>
16+
<div
17+
v-html="sessionDescription"
18+
class="g-agenda-list-item-detail-description"
19+
></div>
1920
<div v-if="session.note" class="g-agenda-list-item-detail-link">
2021
<a :href="session.note">加入此議程的線上共筆</a>
2122
</div>
@@ -28,9 +29,7 @@
2829
<div class="name">
2930
{{ speaker.zh.name }}
3031
</div>
31-
<div class="bio">
32-
{{ speaker.zh.bio }}
33-
</div>
32+
<div v-html="speakerBio" class="bio"></div>
3433
</div>
3534
</div>
3635
</div>
@@ -44,6 +43,7 @@
4443
</template>
4544

4645
<script lang="ts">
46+
import { markdown } from 'markdown';
4747
import { Component, Prop, Watch, Vue } from 'vue-property-decorator';
4848
import CloseIcon from '@/components/icons/Close.vue';
4949
import NextIcon from '@/components/icons/Next.vue';
@@ -73,6 +73,14 @@ export default class AgendaListItemDetail extends Vue {
7373
};
7474
}
7575
76+
get sessionDescription() {
77+
return this.parseDescription(this.session.zh.description);
78+
}
79+
80+
get speakerBio() {
81+
return this.parseDescription(this.speaker.zh.bio);
82+
}
83+
7684
@Watch('value')
7785
private onChangeValue(newValue: boolean) {
7886
this.detailValue = newValue;
@@ -86,6 +94,23 @@ export default class AgendaListItemDetail extends Vue {
8694
private closeDetail() {
8795
this.$emit('input', false);
8896
}
97+
98+
private parseDescription(text: string) {
99+
const styles = Object.entries({
100+
'margin-bottom': '16px',
101+
'font-family': `'Noto Sans TC', sans-serif`,
102+
'font-size': '14px',
103+
'font-weight': 'normal',
104+
'line-height': '1.71',
105+
'letter-spacing': 'normal',
106+
color: '#333943',
107+
})
108+
.map(([k, v]) => `${k}: ${v};`)
109+
.join('');
110+
return markdown
111+
.toHTML(text)
112+
.replace(/<p>/gm, `<p style="${styles}">`);
113+
}
89114
}
90115
</script>
91116

0 commit comments

Comments
 (0)