Skip to content

Commit c03fe5a

Browse files
committed
Merge branch 'feat/math-converter' into chore/all-my-stuffs
# Conflicts: # package.json # pnpm-lock.yaml # src/tools/index.ts
2 parents 0da0839 + 90556e8 commit c03fe5a

File tree

5 files changed

+113
-2
lines changed

5 files changed

+113
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@regexper/render": "^1.0.0",
4646
"@kenjiuno/decompressrtf": "^0.1.4",
4747
"@kenjiuno/msgreader": "^1.22.0",
48+
"@plurimath/plurimath": "^0.2.0",
4849
"@sindresorhus/slugify": "^2.2.1",
4950
"@tabler/icons-vue": "^3.20.0",
5051
"@tiptap/pm": "2.1.6",

pnpm-lock.yaml

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { tool as jsonSizeAnalyzer } from './json-size-analyzer';
2626
import { tool as jsonToCsharp } from './json-to-csharp';
2727
import { tool as luhnValidator } from './luhn-validator';
2828
import { tool as maliciousLinksTester } from './malicious-links-tester';
29+
import { tool as mathFormatsConverter } from './math-formats-converter';
2930

3031
import { tool as cssXpathConverter } from './css-xpath-converter';
3132
import { tool as cssSelectorsMemo } from './css-selectors-memo';
@@ -290,7 +291,12 @@ export const toolsByCategory: ToolCategory[] = [
290291
},
291292
{
292293
name: 'Math',
293-
components: [mathEvaluator, etaCalculator, percentageCalculator],
294+
components: [
295+
mathEvaluator,
296+
etaCalculator,
297+
percentageCalculator,
298+
mathFormatsConverter,
299+
],
294300
},
295301
{
296302
name: 'Measurement',
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { EqualNot } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Math Formats Converter',
6+
path: '/math-formats-converter',
7+
description: 'Convert mathematical expression between formats',
8+
keywords: ['math', 'formats', 'converter', 'latex', 'mathml', 'asciimath', 'omml', 'html'],
9+
component: () => import('./math-formats-converter.vue'),
10+
icon: EqualNot,
11+
createdAt: new Date('2024-05-11'),
12+
});
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<script setup lang="ts">
2+
import Plurimath from '@plurimath/plurimath';
3+
import { useQueryParamOrStorage } from '@/composable/queryParams';
4+
5+
const formats = [
6+
{ value: 'asciimath', label: 'AsciiMath' },
7+
{ value: 'latex', label: 'Latex' },
8+
{ value: 'mathml', label: 'MathML' },
9+
{ value: 'html', label: 'Html' },
10+
{ value: 'omml', label: 'OOML' },
11+
];
12+
13+
const source = ref('');
14+
const sourceFormat = useQueryParamOrStorage({ name: 'src', storageName: 'math-fmts-conv:src', defaultValue: 'latex' });
15+
const targetFormat = useQueryParamOrStorage({ name: 'target', storageName: 'math-fmts-conv:target', defaultValue: 'mathml' });
16+
const target = computedAsync(async () => {
17+
const sourceValue = source.value;
18+
const sourceFormatValue = sourceFormat.value;
19+
const targetFormatValue = targetFormat.value;
20+
if (sourceValue === '') {
21+
return '';
22+
}
23+
if (sourceFormatValue === targetFormatValue) {
24+
return sourceValue;
25+
}
26+
return new Promise<string>((resolve, _reject) => {
27+
try {
28+
const formula = new Plurimath(sourceValue, sourceFormatValue);
29+
let result;
30+
switch (targetFormatValue) {
31+
case 'asciimath':
32+
result = formula.toAsciimath();
33+
break;
34+
case 'latex':
35+
result = formula.toLatex();
36+
break;
37+
case 'mathml':
38+
result = formula.toMathml();
39+
break;
40+
case 'html':
41+
result = formula.toHtml();
42+
break;
43+
case 'omml':
44+
result = formula.toOmml();
45+
break;
46+
default:
47+
result = '# unknown format';
48+
break;
49+
}
50+
resolve(result);
51+
}
52+
catch (e: any) {
53+
resolve(`# error converting formula: ${e.toString()}`);
54+
}
55+
});
56+
});
57+
</script>
58+
59+
<template>
60+
<div>
61+
<c-input-text
62+
v-model:value="source"
63+
multiline
64+
placeholder="Put your math expression here..."
65+
rows="5"
66+
label="Mathematical expression to convert"
67+
raw-text
68+
mb-5
69+
/>
70+
<c-select
71+
v-model:value="sourceFormat"
72+
:options="formats"
73+
placeholder="Source format"
74+
/>
75+
76+
<n-divider />
77+
78+
<c-select
79+
v-model:value="targetFormat"
80+
:options="formats"
81+
placeholder="Source format"
82+
/>
83+
<textarea-copyable v-if="target !== ''" :value="target" :language="targetFormat" />
84+
</div>
85+
</template>

0 commit comments

Comments
 (0)