shortcut_help.cljs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. (ns frontend.components.shortcut-help
  2. "Shortcut help"
  3. (:require [frontend.context.i18n :refer [t]]
  4. [frontend.state :as state]
  5. [frontend.ui :as ui]
  6. [frontend.extensions.latex :as latex]
  7. [frontend.extensions.highlight :as highlight]
  8. [logseq.graph-parser.util.block-ref :as block-ref]
  9. [logseq.graph-parser.util.page-ref :as page-ref]
  10. [rum.core :as rum]
  11. [frontend.components.shortcut :as shortcut]))
  12. (rum/defc trigger-table []
  13. [:table
  14. [:thead
  15. [:tr
  16. [:th.text-left [:b (t :help/shortcuts-triggers)]]
  17. [:th.text-right [:b (t :help/shortcut)]]]]
  18. [:tbody
  19. [:tr
  20. [:td.text-left (t :help/slash-autocomplete)]
  21. [:td.text-right [:code "/"]]]
  22. [:tr
  23. [:td.text-left (t :help/block-content-autocomplete)]
  24. [:td.text-right [:code "<"]]]
  25. [:tr
  26. [:td.text-left (t :help/reference-autocomplete)]
  27. [:td.text-right [:code page-ref/left-and-right-brackets]]]
  28. [:tr
  29. [:td.text-left (t :help/block-reference)]
  30. [:td.text-right [:code block-ref/left-and-right-parens]]]
  31. [:tr
  32. [:td.text-left (t :help/open-link-in-sidebar)]
  33. [:td.text-right [:code "Shift Click"]]]
  34. [:tr
  35. [:td.text-left (t :help/context-menu)]
  36. [:td.text-right [:code "Right Click"]]]]])
  37. (defn markdown-and-orgmode-syntax []
  38. (let [list [:bold :italics :del :mark :latex :code :link :pre :img]
  39. preferred-format (state/get-preferred-format) ; markdown/org
  40. title (case preferred-format
  41. :markdown (t :help/markdown-syntax)
  42. :org (t :help/org-mode-syntax))
  43. learn-more (case preferred-format
  44. :markdown "https://www.markdownguide.org/basic-syntax"
  45. :org "https://orgmode.org/worg/dev/org-syntax.html")
  46. raw (case preferred-format
  47. :markdown {:bold (str "**" (t :bold) "**")
  48. :italics (str "_" (t :italics) "_")
  49. :link "[Link](https://www.example.com)"
  50. :del (str "~~" (t :strikethrough) "~~")
  51. :mark (str "^^" (t :highlight) "^^")
  52. :latex "$$E = mc^2$$"
  53. :code (str "`" (t :code) "`")
  54. :pre "```clojure\n (println \"Hello world!\")\n```"
  55. :img "![image](https://asset.logseq.com/static/img/logo.png)"}
  56. :org {:bold (str "*" (t :bold) "*")
  57. :italics (str "/" (t :italics) "/")
  58. :del (str "+" (t :strikethrough) "+")
  59. :pre [:pre "#+BEGIN_SRC clojure\n (println \"Hello world!\")\n#+END_SRC"]
  60. :link "[[https://www.example.com][Link]]"
  61. :mark (str "^^" (t :highlight) "^^")
  62. :latex "$$E = mc^2$$"
  63. :code "~Code~"
  64. :img "[[https://asset.logseq.com/static/img/logo.png][image]]"})
  65. rendered {:italics [:i (t :italics)]
  66. :bold [:b (t :bold)]
  67. :link [:a {:href "https://www.example.com"} "Link"]
  68. :del [:del (t :strikethrough)]
  69. :mark [:mark (t :highlight)]
  70. :latex (latex/latex "help-latex" "E = mc^2" true false)
  71. :code [:code (t :code)]
  72. :pre (highlight/highlight "help-highlight" {:data-lang "clojure"} "(println \"Hello world!\")")
  73. :img [:img {:style {:float "right" :width 32 :height 32}
  74. :src "https://asset.logseq.com/static/img/logo.png"
  75. :alt "image"}]}]
  76. [:table
  77. [:thead
  78. [:tr
  79. [:th.text-left [:b title]]
  80. [:th.text-right [:a {:href learn-more} "Learn more →"]]]]
  81. [:tbody
  82. (map (fn [name]
  83. [:tr
  84. [:td.text-left [(if (= :pre name) :pre :code) (get raw name)]]
  85. [:td.text-right (get rendered name)]])
  86. list)]]))
  87. (rum/defc shortcut-page
  88. [{:keys [show-title?]
  89. :or {show-title? true}}]
  90. [:div.cp__shortcut-page
  91. (when show-title? [:h1.title (t :help/shortcut-page-title)])
  92. (trigger-table)
  93. (markdown-and-orgmode-syntax)
  94. (shortcut/shortcut-keymap-x)])