6666def ConvertSSMLTextForNVDA (text :str , language :str = "" ):
6767 # MathCAT's default rate is 180 wpm.
6868 # Assume that 0% is 80 wpm and 100% is 450 wpm and scale accordingly.
69- log .info ("Speech str: '{}'" .format (text ))
69+ # log.info("Speech str: '{}'".format(text))
7070 synth = getSynth ()
7171 wpm = synth ._percentToParam (synth .rate , 80 , 450 )
7272 breakMulti = 180.0 / wpm
@@ -118,7 +118,7 @@ def ConvertSSMLTextForNVDA(text:str, language:str=""):
118118 out .extend ((" " , m .group (0 ), " " ))
119119 if language :
120120 out .append (LangChangeCommand (None ))
121- log .info ("Speech commands: '{}'" .format (out ))
121+ # log.info("Speech commands: '{}'".format(out))
122122 return out
123123
124124class MathCATInteraction (mathPres .MathInteractionNVDAObject ):
@@ -132,6 +132,7 @@ class MathCATInteraction(mathPres.MathInteractionNVDAObject):
132132 def __init__ (self , provider = None , mathMl : Optional [str ]= None ):
133133 super (MathCATInteraction , self ).__init__ (provider = provider , mathMl = mathMl )
134134 provider ._setSpeechLanguage (mathMl )
135+ self .init_mathml = mathMl
135136 try :
136137 libmathcat .SetMathML (mathMl )
137138 except Exception as e :
@@ -204,28 +205,38 @@ def script_navigate(self, gesture: KeyboardInputGesture):
204205
205206 _startsWithMath = re .compile ("\\ s*?<math" )
206207 @script (
208+ # For translators: Message to be announced during Keyboard Help
209+ description = _ ("Copy navigation focus to clipboard" ),
210+ # For translators: Name of the section in "Input gestures" dialog.
211+ category = _ ("Clipboard" ),
207212 gesture = "kb:control+c" ,
208213 )
209214 def script_rawdataToClip (self , gesture : KeyboardInputGesture ):
210215 try :
211216 mathml = libmathcat .GetNavigationMathML ()[0 ]
212217 if not re .match (self ._startsWithMath , mathml ):
213- mathml = "<math>" + mathml + "</math>" # copy will fix up name spacing
218+ mathml = "<math>\n " + mathml + "</math>" # copy will fix up name spacing
219+ elif self .init_mathml != '' :
220+ mathml = self .init_mathml
214221 self ._copyToClipAsMathML (mathml )
215222 ui .message (_ ("copy" ))
216223 except Exception as e :
217224 log .error (e )
218225 speech .speakMessage (_ ("unable to copy math: see NVDA error log for details" ))
219226
220227
228+ # not a perfect match sequence, but should capture normal MathML
221229 # not a perfect match sequence, but should capture normal MathML
222230 _mathTagHasNameSpace = re .compile ("<math .*?xmlns.+?>" )
231+ _hasAddedId = re .compile (" id='[^'].+' data-id-added='true'" )
232+ _hasDataAttr = re .compile (" data-[^=]+='[^']*'" )
223233 def _wrapMathMLForClipBoard (self , text : str ) -> str :
224234 # cleanup the MathML a little
225- mathml_with_ns = text .replace (" data-changed='added'" , "" ).replace (" data-id-added='true'" , "" )
226- if not re .match (self ._mathTagHasNameSpace , text ):
227- mathml_with_ns = mathml_with_ns .replace ('math' , 'math xmlns="http://www.w3.org/1998/Math/MathML"' , 1 )
228- return '<?xml version="1.0"?>' + mathml_with_ns
235+ text = re .sub (self ._hasAddedId , "" , text )
236+ mathml_with_ns = re .sub (self ._hasDataAttr , "" , text )
237+ if not re .match (self ._mathTagHasNameSpace , mathml_with_ns ):
238+ mathml_with_ns = mathml_with_ns .replace ('math' , "math xmlns='http://www.w3.org/1998/Math/MathML'" , 1 )
239+ return mathml_with_ns
229240
230241 def _copyToClipAsMathML (self , text : str , notify : Optional [bool ] = False ) -> bool :
231242 """Copies the given text to the windows clipboard.
@@ -242,8 +253,9 @@ def _copyToClipAsMathML(self, text: str, notify: Optional[bool] = False) -> bool
242253 try :
243254 with winUser .openClipboard (gui .mainFrame .Handle ):
244255 winUser .emptyClipboard ()
245- self ._setClipboardData (self .CF_MathML , self ._wrapMathMLForClipBoard (text ))
246- self ._setClipboardData (self .CF_MathML_Presentation , self ._wrapMathMLForClipBoard (text ))
256+ text = self ._wrapMathMLForClipBoard (text )
257+ self ._setClipboardData (self .CF_MathML , '<?xml version="1.0"?>' + text )
258+ self ._setClipboardData (self .CF_MathML_Presentation , '<?xml version="1.0"?>' + text )
247259 self ._setClipboardData (winUser .CF_UNICODETEXT , text )
248260 got = getClipData ()
249261 except OSError :
0 commit comments