code.js 513 B

123456789101112131415161718
  1. import React from "react"
  2. import Action from "./action"
  3. import isUrl from "misago/utils/is-url"
  4. export default function(props) {
  5. return (
  6. <Action execAction={insertCode} title={gettext("Insert code")} {...props}>
  7. <span className="material-icon">functions</span>
  8. </Action>
  9. )
  10. }
  11. export function insertCode(selection, replace) {
  12. const syntax = $.trim(
  13. prompt(gettext("Enter name of syntax of your code (optional)") + ":")
  14. )
  15. replace("\n\n```" + syntax + "\n" + selection + "\n```\n\n")
  16. }