diff --git a/index.js b/index.js index 1a7fa34..5253352 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ import 'dotenv/config' -import { items } from './config.js' +import { items, linkFormat } from './config.js' +import { markdownCharEscape } from './utils.js' const OMGLOL_API = `https://api.omg.lol/address/${process.env.OMGLOL_USERNAME}/now` @@ -36,6 +37,13 @@ export default async function now() { const latest = await getLatest() console.log(`${id}: ${latest.text}`) console.log(`${id} URL: ${latest.url}`) + + // Apply markdown escaping only for markdown links + const displayText = + linkFormat === 'html' + ? latest.text + : markdownCharEscape(latest.text) + if (latest && latest.text && latest.url) { newNow = newNow.replace(regex, (match, openTag, closeTag) => { // Replace href in opening tag @@ -43,7 +51,7 @@ export default async function now() { /href=["'][^"']*["']/, `href="${latest.url}"`, ) - return `${updatedOpenTag}${latest.text}${closeTag}` + return `${updatedOpenTag}${displayText}${closeTag}` }) } } catch (e) {