Skip to content

Commit 04c22c7

Browse files
authored
Merge pull request #1569 from hackmdio/feature/fretboard-improvement
2 parents 374bda0 + 038fac1 commit 04c22c7

File tree

4 files changed

+49
-20
lines changed

4 files changed

+49
-20
lines changed

public/docs/features.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,26 @@ stop
369369
}
370370
```
371371

372+
### Fretboard
373+
374+
```fretboard {title="horizontal, 6 frets, with nut", type="h6"}
375+
-oO-*-
376+
--o-o-
377+
-o-oo-
378+
-o-oO-
379+
-oo-o-
380+
-*O-o-
381+
3
382+
```
383+
372384
> More information about **sequence diagrams** syntax [here](http://bramp.github.io/js-sequence-diagrams/).
373385
> More information about **flow charts** syntax [here](http://adrai.github.io/flowchart.js/).
374386
> More information about **graphviz** syntax [here](http://www.tonyballantyne.com/graphs.html)
375387
> More information about **mermaid** syntax [here](http://mermaid-js.github.io/mermaid)
376388
> More information about **abc** syntax [here](http://abcnotation.com/learn)
377389
> More information about **plantuml** syntax [here](http://plantuml.com/index)
378390
> More information about **vega** syntax [here](https://vega.github.io/vega-lite/docs)
391+
> More information about **fretboard** syntax [here](https://hackmd.io/@docs/fretboard-syntax)
379392
380393
Alert Area
381394
---

public/js/extra.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ export function finishView (view) {
502502
try {
503503
const $ele = $(value).parent().parent()
504504
$ele.html(renderFretBoard($value.text(), params))
505+
$ele.addClass('fretboard')
505506
} catch (err) {
506507
$value.unwrap()
507508
$value.parent().append(`<div class="alert alert-warning">${escapeHTML(err)}</div>`)

public/js/lib/renderer/fretboard/css/i.css

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* -- GENERAL TYPOGRAPHY -- */
22
.fretTitle {
33
color: #555;
4+
text-align: center;
45
font-family: "Helvetica Neue", sans-serif;
5-
background: #eee;
66
line-height: 1.4;
77
font-size: 1.6em;
88
margin: 10px 0 10px 0;
@@ -20,14 +20,19 @@ section {
2020
}
2121

2222
/* Fretboard Container/Wrapper */
23+
24+
.fretContainer, .fretContainer_h {
25+
outline: solid 1px #eeee;
26+
margin: 0 auto;
27+
padding: 15px 0;
28+
}
29+
2330
.fretContainer {
2431
width: 320px;
25-
margin: 0 auto;
2632
}
2733

2834
.fretContainer_h {
2935
max-width: 400px;
30-
margin: 0 auto;
3136
}
3237

3338
@media all and (max-width: 400px) {
@@ -59,7 +64,6 @@ section {
5964
position: absolute;
6065
top: 0;
6166
left: 0;
62-
z-index: 10;
6367
}
6468

6569
.svg_wrapper.v4 {
@@ -181,3 +185,7 @@ section {
181185
}
182186

183187
/*# sourceMappingURL=i.css.map */
188+
189+
.markdown-body pre.fretboard {
190+
background-color: transparent;
191+
}

public/js/lib/renderer/fretboard/fretboard.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,33 @@ const switchListH = {
3232
'\n': `<div class='cell empty'>${dotEmptyH}</div><div class='cell empty'>${dotEmptyH}</div>`
3333
}
3434

35-
export const renderFretBoard = (content, { title: fretTitle, type }) => {
36-
const fretType = type.split(' ')
37-
const containerClass = fretType && fretType[0].startsWith('h') ? 'fretContainer_h' : 'fretContainer'
35+
export const renderFretBoard = (content, { title: fretTitle = '', type = '' }) => {
36+
const isVertical = !(typeof type[0] === 'string' && type[0].startsWith('h'))
37+
38+
const containerClass = isVertical ? 'fretContainer' : 'fretContainer_h'
39+
40+
const [fretType, nutOption] = type.split(' ')
3841
const fretboardHTML = $(`<div class="${containerClass}"></div>`)
3942

40-
$(fretboardHTML).append($(`<div class="fretTitle">${fretTitle}</div>`))
43+
if (fretTitle) {
44+
$(fretboardHTML).append(`<div class="fretTitle">${fretTitle}</div>`)
45+
}
4146

4247
// create fretboard background HTML
43-
const fretbOrientation = fretType && fretType[0].startsWith('v') ? 'vert' : 'horiz'
44-
const fretbLen = fretType && fretType[0].substring(1)
45-
const fretbClass = fretType && fretType[0][0] + ' ' + fretType[0]
46-
const nut = (fretType[1] && fretType[1] === 'noNut') ? 'noNut' : ''
48+
const fretbOrientation = isVertical ? 'vert' : 'horiz'
49+
const fretbLen = fretType && fretType.substring(1)
50+
const fretbClass = fretType && fretType[0] + ' ' + fretType
51+
const nut = nutOption === 'noNut' ? 'noNut' : ''
52+
4753
const svgHTML = $(`<div class="svg_wrapper ${fretbClass} ${nut}"></div>`)
4854
const fretbBg = require(`./svg/fretb_${fretbOrientation}_${fretbLen}.svg`)
55+
4956
$(svgHTML).append($(fretbBg))
5057

5158
// create cells HTML
5259
const cellsHTML = $('<div class="cells"></div>')
53-
let switchList = ''
54-
if (fretbOrientation && fretbOrientation === 'vert') {
60+
let switchList = {}
61+
if (isVertical) {
5562
switchList = switchListV
5663
} else {
5764
// calculate position
@@ -66,16 +73,16 @@ export const renderFretBoard = (content, { title: fretTitle, type }) => {
6673
const numArray = [...Array(10).keys()].slice(1)
6774
contentCell && contentCell.forEach(char => {
6875
if (numArray.toString().indexOf(char) !== -1) {
69-
const numType = fretType && fretType[0].startsWith('h') ? '_h' : ''
76+
const numType = isVertical ? '' : '_h'
7077
const numSvg = require(`./svg/number${char}${numType}.svg`)
71-
cellsHTML.append($(`<div class='cell empty'>${numSvg}</div>`))
72-
} else if (switchList[char] !== undefined) {
73-
cellsHTML.append($(switchList[char]))
78+
cellsHTML.append(`<div class='cell empty'>${numSvg}</div>`)
79+
} else if (typeof switchList[char] !== 'undefined') {
80+
cellsHTML.append(switchList[char])
7481
}
7582
})
7683

77-
$(svgHTML).append($(cellsHTML))
78-
$(fretboardHTML).append($(svgHTML))
84+
$(svgHTML).append(cellsHTML)
85+
$(fretboardHTML).append(svgHTML)
7986

8087
return fretboardHTML[0].outerHTML
8188
}

0 commit comments

Comments
 (0)