Fossil SCM

The <mark> HTML tag flows through to the output in html_to_plaintext() if the output is not going to a VT-100 terminal.

drh 2025-03-22 11:08 trunk
Commit a9805669918097942759f44935fd79cb6c2c365eb008a9649d2a82be9595fb80
1 file changed +19 -9
+19 -9
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -2524,10 +2524,22 @@
25242524
*/
25252525
#define HTOT_VT100 0x0001 /* <mark> becomes ^[[91m */
25262526
#define HTOT_NO_WS 0x0002 /* Collapse whitespace to a single space */
25272527
25282528
#endif /* INTERFACE */
2529
+
2530
+/*
2531
+** Add <MARK> or </MARK> to the output, or similar VT-100 escape
2532
+** codes.
2533
+*/
2534
+static void addMark(Blob *pOut, int mFlags, int isClose){
2535
+ static const char *az[4] = { "<MARK>", "</MARK>", "\033[91m", "\033[0m" };
2536
+ int i = 0;
2537
+ if( isClose ) i++;
2538
+ if( mFlags & HTOT_VT100 ) i += 2;
2539
+ blob_append(pOut, az[i], -1);
2540
+}
25292541
25302542
/*
25312543
** Remove all HTML markup from the input text. The output written into
25322544
** pOut is pure text.
25332545
**
@@ -2568,18 +2580,16 @@
25682580
}
25692581
if( zIn[0]=='<' ) zIn += n;
25702582
continue;
25712583
}
25722584
if( eTag==MARKUP_INVALID && strcmp(zTag,"mark")==0 ){
2573
- if( (mFlags & HTOT_VT100)!=0 ){
2574
- if( isCloseTag && nMark ){
2575
- blob_append(pOut, "\033[0m", 4);
2576
- nMark = 0;
2577
- }else if( !isCloseTag && !nMark ){
2578
- blob_append(pOut, "\033[91m", 5);
2579
- nMark = 1;
2580
- }
2585
+ if( isCloseTag && nMark ){
2586
+ addMark(pOut, mFlags, 1);
2587
+ nMark = 0;
2588
+ }else if( !isCloseTag && !nMark ){
2589
+ addMark(pOut, mFlags, 0);
2590
+ nMark = 1;
25812591
}
25822592
zIn += n;
25832593
continue;
25842594
}
25852595
if( eTag==MARKUP_TITLE ){
@@ -2658,11 +2668,11 @@
26582668
nNL = nWS = 0;
26592669
blob_append(pOut, zIn, n);
26602670
}
26612671
zIn += n;
26622672
}
2663
- if( nMark ) blob_append(pOut, "\033[0m", 4);
2673
+ if( nMark ) addMark(pOut, mFlags, 1);
26642674
if( nNL==0 ) blob_append_char(pOut, '\n');
26652675
}
26662676
26672677
/*
26682678
** COMMAND: test-html-to-text
26692679
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -2524,10 +2524,22 @@
2524 */
2525 #define HTOT_VT100 0x0001 /* <mark> becomes ^[[91m */
2526 #define HTOT_NO_WS 0x0002 /* Collapse whitespace to a single space */
2527
2528 #endif /* INTERFACE */
 
 
 
 
 
 
 
 
 
 
 
 
2529
2530 /*
2531 ** Remove all HTML markup from the input text. The output written into
2532 ** pOut is pure text.
2533 **
@@ -2568,18 +2580,16 @@
2568 }
2569 if( zIn[0]=='<' ) zIn += n;
2570 continue;
2571 }
2572 if( eTag==MARKUP_INVALID && strcmp(zTag,"mark")==0 ){
2573 if( (mFlags & HTOT_VT100)!=0 ){
2574 if( isCloseTag && nMark ){
2575 blob_append(pOut, "\033[0m", 4);
2576 nMark = 0;
2577 }else if( !isCloseTag && !nMark ){
2578 blob_append(pOut, "\033[91m", 5);
2579 nMark = 1;
2580 }
2581 }
2582 zIn += n;
2583 continue;
2584 }
2585 if( eTag==MARKUP_TITLE ){
@@ -2658,11 +2668,11 @@
2658 nNL = nWS = 0;
2659 blob_append(pOut, zIn, n);
2660 }
2661 zIn += n;
2662 }
2663 if( nMark ) blob_append(pOut, "\033[0m", 4);
2664 if( nNL==0 ) blob_append_char(pOut, '\n');
2665 }
2666
2667 /*
2668 ** COMMAND: test-html-to-text
2669
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -2524,10 +2524,22 @@
2524 */
2525 #define HTOT_VT100 0x0001 /* <mark> becomes ^[[91m */
2526 #define HTOT_NO_WS 0x0002 /* Collapse whitespace to a single space */
2527
2528 #endif /* INTERFACE */
2529
2530 /*
2531 ** Add <MARK> or </MARK> to the output, or similar VT-100 escape
2532 ** codes.
2533 */
2534 static void addMark(Blob *pOut, int mFlags, int isClose){
2535 static const char *az[4] = { "<MARK>", "</MARK>", "\033[91m", "\033[0m" };
2536 int i = 0;
2537 if( isClose ) i++;
2538 if( mFlags & HTOT_VT100 ) i += 2;
2539 blob_append(pOut, az[i], -1);
2540 }
2541
2542 /*
2543 ** Remove all HTML markup from the input text. The output written into
2544 ** pOut is pure text.
2545 **
@@ -2568,18 +2580,16 @@
2580 }
2581 if( zIn[0]=='<' ) zIn += n;
2582 continue;
2583 }
2584 if( eTag==MARKUP_INVALID && strcmp(zTag,"mark")==0 ){
2585 if( isCloseTag && nMark ){
2586 addMark(pOut, mFlags, 1);
2587 nMark = 0;
2588 }else if( !isCloseTag && !nMark ){
2589 addMark(pOut, mFlags, 0);
2590 nMark = 1;
 
 
2591 }
2592 zIn += n;
2593 continue;
2594 }
2595 if( eTag==MARKUP_TITLE ){
@@ -2658,11 +2668,11 @@
2668 nNL = nWS = 0;
2669 blob_append(pOut, zIn, n);
2670 }
2671 zIn += n;
2672 }
2673 if( nMark ) addMark(pOut, mFlags, 1);
2674 if( nNL==0 ) blob_append_char(pOut, '\n');
2675 }
2676
2677 /*
2678 ** COMMAND: test-html-to-text
2679

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button