Skip to content
Snippets Groups Projects
Commit 90705cc1 authored by Ole Voldsæter's avatar Ole Voldsæter
Browse files

fikser meta#272

parent a280526e
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<script> <script>
import entities from '../utils/entities.js' import entities from '../utils/entities.js'
import helpers from '../utils/helpers.js'
export default { export default {
name: 'DefElement', name: 'DefElement',
...@@ -53,7 +54,7 @@ export default { ...@@ -53,7 +54,7 @@ export default {
else if (item.type_ == 'superscript') return {type: item.type_, html: item.text, tag: 'sup'} else if (item.type_ == 'superscript') return {type: item.type_, html: item.text, tag: 'sup'}
else if (item.type_ == 'subscript') return {type: item.type_, html: item.text, 'tag': 'sub'} else if (item.type_ == 'subscript') return {type: item.type_, html: item.text, 'tag': 'sub'}
else if (item.type_ == 'quote_inset') return {type: item.type_, body: item, html: '', tag: 'DefElement', props: {body: item, tag: 'i'}} else if (item.type_ == 'quote_inset') return {type: item.type_, body: item, html: '', tag: 'DefElement', props: {body: item, tag: 'i'}}
else if (item.type_ == 'fraction') return {type: item.type_, html: '', num: item.numerator, denom: item.denominator} else if (item.type_ == 'fraction') return helpers.fraction(item.numerator, item.denominator)
else if (item.id) return {type: item.type_, html: (entities[lang][item.id] || {})['expansion'] || item.id} else if (item.id) return {type: item.type_, html: (entities[lang][item.id] || {})['expansion'] || item.id}
else return {type: item.type_ || 'plain', html: item} else return {type: item.type_ || 'plain', html: item}
} }
......
...@@ -71,4 +71,121 @@ var group_list = function(grps, dictionary) { ...@@ -71,4 +71,121 @@ var group_list = function(grps, dictionary) {
return Array.from(grp_collection).join(' - ') return Array.from(grp_collection).join(' - ')
} }
export default { group_list} var fraction = function(numerator, denominator) {
var superscript = {
'0': '',
'1': '¹',
'2': '²',
'3': '³',
'4': '',
'5': '',
'6': '',
'7': '',
'8': '',
'9': '',
'+': '',
'-': '',
'=': '',
'(': '',
')': '',
'a': '',
'b': '',
'c': '',
'd': '',
'e': '',
'f': '',
'g': '',
'h': 'ʰ',
'i': '',
'j': 'ʲ',
'k': '',
'l': 'ˡ',
'm': '',
'n': '',
'o': '',
'p': '',
'r': 'ʳ',
's': 'ˢ',
't': '',
'u': '',
'v': '',
'w': 'ʷ',
'x': 'ˣ',
'y': 'ʸ',
'z': '',
' ': ' '
}
var subscript = {
'0': '',
'1': '',
'2': '',
'3': '',
'4': '',
'5': '',
'6': '',
'7': '',
'8': '',
'9': '',
'+': '',
'-': '',
'=': '',
'(': '',
')': '',
'a': '',
'e': '',
'h': '',
'i': '',
'j': '',
'k': '',
'l': '',
'm': '',
'n': '',
'o': '',
'p': '',
'r': '',
's': '',
't': '',
'u': '',
'v': '',
'x': '',
' ': ' '
};
var fractions = {
'1/2': '½',
'1/3': '',
'2/3': '',
'1/4': '¼',
'3/4': '¾',
'1/5': '',
'2/5': '',
'3/5': '',
'4/5': '',
'1/6': '',
'5/6': '',
'1/7': '',
'1/8': '',
'3/8': '',
'5/8': '',
'7/8': '',
'1/9': '',
'1/10': ''
};
let other_fraction = null
let num_sup = numerator.toString().split('').map(x => superscript[x] || '_').join('')
let den_sub = denominator.toString().split('').map(x => subscript[x] || '_').join('')
if (! num_sup.includes('_') && ! den_sub.includes('_')) {
other_fraction = num_sup + '' + den_sub
}
return fractions[numerator + '/' + denominator] && {type: 'plain', html: fractions[numerator + '/' + denominator] }
|| other_fraction && {type: 'plain', html: other_fraction }
|| {type: 'fraction', html: '', num: numerator, denom: denominator}
}
export default { group_list, fraction }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment