Skip to content

Commit 6b8950d

Browse files
authored
Merge pull request #1481 from ghost/lang-attr
2 parents 1bdedf1 + 9b899c7 commit 6b8950d

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

public/js/extra.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { renderFretBoard } from './lib/renderer/fretboard/fretboard'
2727
import './lib/renderer/lightbox'
2828
import { renderCSVPreview } from './lib/renderer/csvpreview'
2929

30+
import { escapeAttrValue } from './render'
31+
3032
import markdownit from 'markdown-it'
3133
import markdownitContainer from 'markdown-it-container'
3234

@@ -202,18 +204,15 @@ export function parseMeta (md, edit, view, toc, tocAffix) {
202204
dir = meta.dir
203205
breaks = meta.breaks
204206
}
205-
// text language
206-
if (lang && typeof lang === 'string') {
207-
view.attr('lang', lang)
208-
toc.attr('lang', lang)
209-
tocAffix.attr('lang', lang)
210-
if (edit) { edit.attr('lang', lang) }
211-
} else {
212-
view.removeAttr('lang')
213-
toc.removeAttr('lang')
214-
tocAffix.removeAttr('lang')
215-
if (edit) { edit.removeAttr('lang', lang) }
207+
if (!lang || typeof lang !== 'string') {
208+
lang = 'en'
216209
}
210+
// text language
211+
view.attr('lang', lang)
212+
toc.attr('lang', lang)
213+
tocAffix.attr('lang', lang)
214+
if (edit) { edit.attr('lang', lang) }
215+
217216
// text direction
218217
if (dir && typeof dir === 'string') {
219218
view.attr('dir', dir)
@@ -817,8 +816,8 @@ export function exportToHTML (view) {
817816
html: src[0].outerHTML,
818817
'ui-toc': toc.html(),
819818
'ui-toc-affix': tocAffix.html(),
820-
lang: (md && md.meta && md.meta.lang) ? `lang="${md.meta.lang}"` : null,
821-
dir: (md && md.meta && md.meta.dir) ? `dir="${md.meta.dir}"` : null
819+
lang: (md && md.meta && md.meta.lang) ? `lang="${escapeAttrValue(md.meta.lang)}"` : null,
820+
dir: (md && md.meta && md.meta.dir) ? `dir="${escapeAttrValue(md.meta.dir)}"` : null
822821
}
823822
const html = template(context)
824823
// console.log(html);

public/views/codimd.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="<%= getLocale() %>">
33

44
<head>
55
<%- include codimd/head %>

public/views/error.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="<%= getLocale() %>">
33

44
<head>
55
<%- include codimd/head %>

public/views/index.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="<%= getLocale() %>">
33

44
<head>
55
<%- include index/head %>

public/views/pretty.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="<%= getLocale() %>">
33

44
<head>
55
<meta charset="utf-8">

public/views/slide.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<html lang="en">
2+
<html lang="<%= getLocale() %>">
33
<head>
44
<meta charset="utf-8">
55
<meta name="apple-mobile-web-app-capable" content="yes">

0 commit comments

Comments
 (0)