24
24
using Helper ;
25
25
using System . Threading ;
26
26
using System . Web ;
27
+ using GenerateHighlightContent ;
27
28
28
29
#pragma warning disable CS3003 // Type is not CLS-compliant
29
30
@@ -153,7 +154,7 @@ private void ShowForm()
153
154
154
155
if ( File . Exists ( fileName ) )
155
156
{
156
- InsertHighLightCodeToCurrentSide ( fileName ) ;
157
+ InsertHighLightCodeToCurrentSide ( fileName , form . Parameters ) ;
157
158
}
158
159
}
159
160
@@ -189,7 +190,7 @@ public IStream GetImage(string imageName)
189
190
/// 插入 HighLight Code 至滑鼠游標的位置
190
191
/// Insert HighLight Code To Mouse Position
191
192
/// </summary>
192
- private void InsertHighLightCodeToCurrentSide ( string fileName )
193
+ private void InsertHighLightCodeToCurrentSide ( string fileName , HighLightParameter parameters )
193
194
{
194
195
// Trace.TraceInformation(System.Reflection.MethodBase.GetCurrentMethod().Name);
195
196
string htmlContent = File . ReadAllText ( fileName , Encoding . UTF8 ) ;
@@ -218,7 +219,7 @@ private void InsertHighLightCodeToCurrentSide(string fileName)
218
219
219
220
string [ ] position = GetMousePointPosition ( existingPageId ) ;
220
221
221
- var page = InsertHighLightCode ( htmlContent , position ) ;
222
+ var page = InsertHighLightCode ( htmlContent , position , parameters ) ;
222
223
page . Root . SetAttributeValue ( "ID" , existingPageId ) ;
223
224
224
225
OneNoteApplication . UpdatePageContent ( page . ToString ( ) , DateTime . MinValue ) ;
@@ -254,21 +255,98 @@ private string[] GetMousePointPosition(string pageID)
254
255
/// 產生 XML 插入至 OneNote
255
256
/// Generate XML Insert To OneNote
256
257
/// </summary>
257
- public XDocument InsertHighLightCode ( string htmlContent , string [ ] position )
258
+ public XDocument InsertHighLightCode ( string htmlContent , string [ ] position , HighLightParameter parameters )
258
259
{
259
260
XElement children = new XElement ( ns + "OEChildren" ) ;
260
261
262
+ XElement table = new XElement ( ns + "Table" ) ;
263
+ table . Add ( new XAttribute ( "bordersVisible" , "false" ) ) ;
264
+
265
+ XElement columns = new XElement ( ns + "Columns" ) ;
266
+ XElement column1 = new XElement ( ns + "Column" ) ;
267
+ column1 . Add ( new XAttribute ( "index" , "0" ) ) ;
268
+ column1 . Add ( new XAttribute ( "width" , "40" ) ) ;
269
+ if ( parameters . ShowLineNumber )
270
+ {
271
+ columns . Add ( column1 ) ;
272
+ }
273
+ XElement column2 = new XElement ( ns + "Column" ) ;
274
+ if ( parameters . ShowLineNumber )
275
+ {
276
+ column2 . Add ( new XAttribute ( "index" , "1" ) ) ;
277
+ }
278
+ else
279
+ {
280
+ column2 . Add ( new XAttribute ( "index" , "0" ) ) ;
281
+ }
282
+
283
+ column2 . Add ( new XAttribute ( "width" , "1400" ) ) ;
284
+ columns . Add ( column2 ) ;
285
+
286
+ table . Add ( columns ) ;
287
+
288
+ Color color = parameters . HighlightColor ;
289
+ string colorString = string . Format ( "#{0:X2}{1:X2}{2:X2}" , color . R , color . G , color . B ) ;
290
+
291
+ XElement row = new XElement ( ns + "Row" ) ;
292
+ XElement cell1 = new XElement ( ns + "Cell" ) ;
293
+ cell1 . Add ( new XAttribute ( "shadingColor" , colorString ) ) ;
294
+ XElement cell2 = new XElement ( ns + "Cell" ) ;
295
+ cell2 . Add ( new XAttribute ( "shadingColor" , colorString ) ) ;
296
+
261
297
var arrayLine = htmlContent . Split ( new string [ ] { Environment . NewLine } , StringSplitOptions . None ) ;
262
298
foreach ( var item in arrayLine )
263
299
{
300
+ var itemNr = "" ;
301
+ var itemLine = "" ;
302
+ if ( parameters . ShowLineNumber )
303
+ {
304
+ if ( item . Contains ( "</span>" ) )
305
+ {
306
+ int ind = item . IndexOf ( "</span>" ) ;
307
+ itemNr = item . Substring ( 0 , ind + ( "</span>" ) . Length ) ;
308
+ itemLine = item . Substring ( ind ) ;
309
+ }
310
+ else
311
+ {
312
+ itemNr = "" ;
313
+ itemLine = item ;
314
+ }
315
+
316
+ string nr = string . Format ( @"<body style=""font-family:{0}"">" , GenerateHighlightContent . GenerateHighLight . Config . OutputArguments [ "Font" ] . Value ) +
317
+ itemNr . Replace ( "'" , "'" ) + "</body>" ;
318
+
319
+ cell1 . Add ( new XElement ( ns + "OEChildren" ,
320
+ new XElement ( ns + "OE" ,
321
+ new XElement ( ns + "T" ,
322
+ new XCData ( nr ) ) ) ) ) ;
323
+ }
324
+ else
325
+ {
326
+ itemLine = item ;
327
+ }
264
328
//string s = item.Replace(@"style=""", string.Format(@"style=""font-family:{0}; ", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value));
265
329
string s = string . Format ( @"<body style=""font-family:{0}"">" , GenerateHighlightContent . GenerateHighLight . Config . OutputArguments [ "Font" ] . Value ) +
266
- HttpUtility . HtmlDecode ( item ) + "</body>" ;
267
- children . Add ( new XElement ( ns + "OE" ,
330
+ itemLine . Replace ( "'" , "'" ) + "</body>" ;
331
+
332
+ cell2 . Add ( new XElement ( ns + "OEChildren" ,
333
+ new XElement ( ns + "OE" ,
268
334
new XElement ( ns + "T" ,
269
- new XCData ( s ) ) ) ) ;
335
+ new XCData ( s ) ) ) ) ) ;
336
+
270
337
}
271
338
339
+ if ( parameters . ShowLineNumber )
340
+ {
341
+ row . Add ( cell1 ) ;
342
+ }
343
+ row . Add ( cell2 ) ;
344
+
345
+ table . Add ( row ) ;
346
+
347
+ children . Add ( new XElement ( ns + "OE" ,
348
+ table ) ) ;
349
+
272
350
XElement outline = new XElement ( ns + "Outline" ) ;
273
351
274
352
if ( position != null && position . Length == 2 )
@@ -277,6 +355,11 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position)
277
355
pos . Add ( new XAttribute ( "x" , position [ 0 ] ) ) ;
278
356
pos . Add ( new XAttribute ( "y" , position [ 1 ] ) ) ;
279
357
outline . Add ( pos ) ;
358
+
359
+ XElement size = new XElement ( ns + "Size" ) ;
360
+ size . Add ( new XAttribute ( "width" , "1600" ) ) ;
361
+ size . Add ( new XAttribute ( "height" , "200" ) ) ;
362
+ outline . Add ( size ) ;
280
363
}
281
364
outline . Add ( children ) ;
282
365
0 commit comments