Skip to content

Commit d9851f2

Browse files
committed
Support embed OSM
Signed-off-by: Yukai Huang <yukaihuangtw@gmail.com>
1 parent 6ef0d86 commit d9851f2

5 files changed

Lines changed: 35 additions & 2 deletions

File tree

public/css/extra.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
width: 100%;
8080
height: 100%;
8181
}
82+
.geo-map {
83+
width: 100%;
84+
height: 250px;
85+
}
8286

8387
.MJX_Assistive_MathML {
8488
display: none;

public/css/markdown.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
.markdown-body pre.graphviz,
128128
.markdown-body pre.mermaid,
129129
.markdown-body pre.abc,
130+
.markdown-body pre.geo,
130131
.markdown-body pre.vega {
131132
text-align: center;
132133
background-color: inherit;

public/css/slide.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ pre.sequence-diagram,
224224
pre.graphviz,
225225
pre.mermaid,
226226
pre.abc,
227+
pre.geo,
227228
pre.vega {
228229
text-align: center;
229230
background-color: white;

public/js/extra.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-env browser, jquery */
2-
/* global moment, serverurl, plantumlServer */
2+
/* global moment, serverurl, plantumlServer, L */
33

44
import Prism from 'prismjs'
55
import hljs from 'highlight.js'
@@ -453,6 +453,31 @@ export function finishView (view) {
453453
console.warn(err)
454454
}
455455
})
456+
view.find('div.geo.raw').removeClass('raw').each(function (key, value) {
457+
const $elem = $(value).parent().parent()
458+
const $value = $(value)
459+
const content = $value.text()
460+
try {
461+
if (content.match(/[\d\.\,]+/)) {
462+
const [lng, lat, zoom] = content.split(',').map(parseFloat)
463+
const position = [lat, lng]
464+
$elem.html(`<div class="geo-map"></div>`)
465+
const map = L.map($elem.find('.geo-map')[0]).setView(position, zoom || 16)
466+
467+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
468+
attribution: '<a href="https://www.openstreetmap.org/">OSM</a>',
469+
maxZoom: 18,
470+
}).addTo(map)
471+
L.marker(position).addTo(map)
472+
$elem.addClass('geo')
473+
}
474+
} catch (err) {
475+
$elem.append(`<div class="alert alert-warning">${escapeHTML(err)}</div>`)
476+
console.warn(err)
477+
}
478+
})
479+
480+
456481
// image href new window(emoji not included)
457482
const images = view.find('img.raw[src]').removeClass('raw')
458483
images.each((key, value) => {
@@ -1013,6 +1038,8 @@ function highlightRender (code, lang) {
10131038
return `<div class="abc raw">${code}</div>`
10141039
} else if (lang === 'vega') {
10151040
return `<div class="vega raw">${code}</div>`
1041+
} else if (lang === 'geo') {
1042+
return `<div class="geo raw">${code}</div>`
10161043
}
10171044
const result = {
10181045
value: code

public/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ var cursorActivityDebounce = 50
101101
var cursorAnimatePeriod = 100
102102
var supportContainers = ['success', 'info', 'warning', 'danger', 'spoiler']
103103
var supportCodeModes = ['javascript', 'typescript', 'jsx', 'htmlmixed', 'htmlembedded', 'css', 'xml', 'clike', 'clojure', 'ruby', 'python', 'shell', 'php', 'sql', 'haskell', 'coffeescript', 'yaml', 'pug', 'lua', 'cmake', 'nginx', 'perl', 'sass', 'r', 'dockerfile', 'tiddlywiki', 'mediawiki', 'go', 'gherkin'].concat(hljs.listLanguages())
104-
var supportCharts = ['sequence', 'flow', 'graphviz', 'mermaid', 'abc', 'plantuml', 'vega']
104+
var supportCharts = ['sequence', 'flow', 'graphviz', 'mermaid', 'abc', 'plantuml', 'vega', 'geo']
105105
var supportHeaders = [
106106
{
107107
text: '# h1',

0 commit comments

Comments
 (0)