Skip to content

Commit

Permalink
Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
madprops committed Jan 18, 2025
1 parent 8690e31 commit 31dbeeb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ And words or phrases between two asterisks (**) get bold.

---

`color_backticks` : Color used for backticks markdown.

---

`color_quotes` : Color used for quotes markdown.

---

## Permissions <a name="permissions"></a>

Access to ai and rules can be defined.
Expand Down Expand Up @@ -737,17 +745,17 @@ For example `!multiprocess true`. Or set the config file.

There is translation of some markdown syntax to effects like bold or color.

These include backticks, asterisks, and underscores.
These include backticks, asterisks, underscores and quotes.

For example `*this thing*` will turn bold, using irc escape codes.

Or \`this thing` will turn green.

Or `_this thing_` will turn bold too.

There is only one color used, and it can be configured.
Quotes change the color but they also include the full text (includes the quotes).

Basically backticks turn things into color, the rest make it bold.
The color of backticks and quotes can be configured through `color_backticks` and `color_quotes` configs.

---

Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
"talk_limit": 1,
"multiprocess": false,
"markdown": true,
"markdown_color": "green"
"color_backticks": "green",
"color_quotes": "cyan"
}
33 changes: 23 additions & 10 deletions modules/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,42 @@ module.exports = (App) => {
}

App.format_irc = (text) => {
let color = App.config.markdown_color
let color_func = App[`irc_color_${color}`]

function char_regex(char) {
let c = App.escape_regex(char)
let regex = new RegExp(`(?:(?<=\\s|^|\\(|\\[|\\/)${c}([a-zA-Z- ]+)${c}(?=\\s|$|\\.|,|;|!|\\?|:|\\/|\\)|\\]|…))`)
return new RegExp(regex, `g`)
}

function action(regex, func) {
function action(regex, mode, full = false) {
let func

if (mode === `bold`) {
func = App.irc_bold
}
else {
func = App[`irc_color_${mode}`]
}

let match = regex.exec(text)

while (match) {
text = text.replace(match[0], func(match[1]))
if (full) {
text = text.replace(match[0], func(match[0]))
}
else {
text = text.replace(match[0], func(match[1]))
}

match = regex.exec(text)
}
}

action(char_regex(`\``), color_func)
action(char_regex(`**`), App.irc_bold)
action(char_regex(`*`), App.irc_bold)
action(char_regex(`__`), App.irc_bold)
action(char_regex(`_`), App.irc_bold)
action(char_regex(`\``), App.config.color_backticks)
action(char_regex(`"`), App.config.color_quotes, true)
action(char_regex(`**`), `bold`)
action(char_regex(`*`), `bold`)
action(char_regex(`__`), `bold`)
action(char_regex(`_`), `bold`)

return text
}
Expand Down

0 comments on commit 31dbeeb

Please sign in to comment.