@@ -5,6 +5,7 @@ import {ExtensionsManager} from '../../../core';
55import { BaseNode , BaseSchemaSpecs } from '../../base/specs' ;
66
77import { MathNode , MathSpecs } from './MathSpecs' ;
8+ import { isLatexMode , parseLatexFormulas } from './utils' ;
89
910const {
1011 schema,
@@ -47,3 +48,46 @@ describe('Math extension', () => {
4748 same ( `$$${ formula } $$\n\n` , doc ( mathB ( formula ) ) ) ;
4849 } ) ;
4950} ) ;
51+
52+ describe ( 'latex-paste-plugin utilities' , ( ) => {
53+ describe ( 'isLatexMode' , ( ) => {
54+ it ( 'should return true for tex/latex modes' , ( ) => {
55+ expect ( isLatexMode ( 'tex' ) ) . toBe ( true ) ;
56+ expect ( isLatexMode ( 'latex' ) ) . toBe ( true ) ;
57+ expect ( isLatexMode ( 'bibtex' ) ) . toBe ( true ) ;
58+ } ) ;
59+
60+ it ( 'should return false for non-latex modes' , ( ) => {
61+ expect ( isLatexMode ( 'javascript' ) ) . toBe ( false ) ;
62+ expect ( isLatexMode ( 'python' ) ) . toBe ( false ) ;
63+ expect ( isLatexMode ( undefined ) ) . toBe ( false ) ;
64+ } ) ;
65+ } ) ;
66+
67+ describe ( 'parseLatexFormulas' , ( ) => {
68+ it ( 'should split formulas by double newlines' , ( ) => {
69+ const input = 'E = mc^2\n\ne^{i\\pi} + 1 = 0' ;
70+ const result = parseLatexFormulas ( input ) ;
71+ expect ( result ) . toEqual ( [ 'E = mc^2' , 'e^{i\\pi} + 1 = 0' ] ) ;
72+ } ) ;
73+
74+ it ( 'should preserve comment lines starting with %' , ( ) => {
75+ const input = `% Einstein equation
76+ E = mc^2
77+
78+ % Euler formula
79+ e^{i\\pi} + 1 = 0` ;
80+ const result = parseLatexFormulas ( input ) ;
81+ expect ( result ) . toEqual ( [
82+ '% Einstein equation\nE = mc^2' ,
83+ '% Euler formula\ne^{i\\pi} + 1 = 0' ,
84+ ] ) ;
85+ } ) ;
86+
87+ it ( 'should return comments as formulas' , ( ) => {
88+ const input = '% Comment 1\n% Comment 2' ;
89+ const result = parseLatexFormulas ( input ) ;
90+ expect ( result ) . toEqual ( [ '% Comment 1\n% Comment 2' ] ) ;
91+ } ) ;
92+ } ) ;
93+ } ) ;
0 commit comments