MCPcopy Index your code
hub / github.com/ether/etherpad / getTXTFromAtext

Function getTXTFromAtext

src/node/utils/ExportTxt.ts:47–263  ·  view source on GitHub ↗
(pad: PadType, atext: AText, authorColors?:string)

Source from the content-addressed store, hash-verified

45// This is different than the functionality provided in ExportHtml as it provides formatting
46// functionality that is designed specifically for TXT exports
47const getTXTFromAtext = (pad: PadType, atext: AText, authorColors?:string) => {
48 const apool = pad.apool();
49 const textLines = atext.text.slice(0, -1).split('\n');
50 const attribLines = splitAttributionLines(atext.attribs, atext.text);
51
52 const props = ['heading1', 'heading2', 'bold', 'italic', 'underline', 'strikethrough'];
53 const anumMap: MapType = {};
54 const css = '';
55
56 props.forEach((propName, i) => {
57 // @ts-ignore
58 const propTrueNum = apool.putAttrib([propName, true], true);
59 if (propTrueNum >= 0) {
60 anumMap[propTrueNum] = i;
61 }
62 });
63
64 const getLineTXT = (text:string, attribs:any) => {
65 const propVals:(number|boolean)[] = [false, false, false];
66 const ENTER = 1;
67 const STAY = 2;
68 const LEAVE = 0;
69
70 // Use order of tags (b/i/u) as order of nesting, for simplicity
71 // and decent nesting. For example,
72 // <b>Just bold<b> <b><i>Bold and italics</i></b> <i>Just italics</i>
73 // becomes
74 // <b>Just bold <i>Bold and italics</i></b> <i>Just italics</i>
75 const taker = new StringIterator(text);
76 const assem = new StringAssembler();
77
78 let idx = 0;
79
80 const processNextChars = (numChars: number) => {
81 if (numChars <= 0) {
82 return;
83 }
84
85 const ops = deserializeOps(subattribution(attribs, idx, idx + numChars));
86 idx += numChars;
87
88 for (const o of ops) {
89 let propChanged = false;
90
91 for (const a of attributes.decodeAttribString(o.attribs)) {
92 if (a in anumMap) {
93 const i = anumMap[a] as number; // i = 0 => bold, etc.
94
95 if (!propVals[i]) {
96 propVals[i] = ENTER;
97 propChanged = true;
98 } else {
99 propVals[i] = STAY;
100 }
101 }
102 }
103
104 for (let i = 0; i < propVals.length; i++) {

Callers 1

getPadTXTFunction · 0.85

Calls 6

splitAttributionLinesFunction · 0.90
getLineTXTFunction · 0.85
apoolMethod · 0.80
sliceMethod · 0.80
putAttribMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected