bluesky quote bot
at main 43 lines 1.4 kB view raw
1export function generateStyledHTML(input: string): string { 2 // First, replace the escaped newlines (\\n) with actual newlines (\n) 3 input = input.replace(/\\n/g, "\n"); 4 5 // Split the input into paragraphs based on \n, and apply italics for *text* 6 const paragraphs = input 7 .split("\n") // Split by newline characters 8 .map((paragraph) => 9 paragraph.replace(/\*(.*?)\*/g, '<span class="it">$1</span>') // Apply italics 10 ) 11 .map((paragraph) => `<p>${paragraph}</p>`) // Wrap each in <p> tags 12 .join(""); // Join the paragraphs into one string 13 14 // Combine HTML and CSS into one string 15 const combinedHTML = ` 16 <div class="styled-container"> 17 <style> 18 .styled-container { 19 font-size: clamp(14px, 12px + 0.75vw, 20px); 20 padding: 40px; 21 max-width: 620px; 22 background: ivory; 23 font-family: 'Merriweather', serif; 24 line-height: 1.5; 25 text-align: justify; 26 hyphens: auto; 27 text-indent: 1.5em; 28 } 29 30 .styled-container p { 31 margin-block-start: 0; 32 margin-block-end: 0; 33 } 34 35 .styled-container .it { 36 font-style: italic; 37 } 38 </style> 39 ${paragraphs} 40 </div>`; 41 42 return combinedHTML; 43}