This commit is contained in:
sankalp committed 2024-07-12 12:44:18 +05:45
1 parent 8b0cde6e86
commit 0389156702
10 files changed
+281 -120

No files matched your search

@@ -6,9 +6,9 @@ const { execAsync, exec } = Utils;
import { MaterialIcon } from "icons.ts";
import md2pango from "./md2pango.ts";
import { theme } from "variables.ts";
import Pango10 from "gi://Pango?version=1.0";
const LATEX_DIR = `${GLib.get_user_cache_dir()}/ags/media/latex`;
const CUSTOM_SCHEME_ID = `custom${theme.value == "dark" ? "" : "-light"}`;
const USERNAME = GLib.get_user_name();
function substituteLang(str) {
@@ -29,10 +29,11 @@ const HighlightedCode = (content, lang) => {
wrap_mode: Gtk.WrapMode.NONE
});
const langManager = GtkSource.LanguageManager.get_default();
let displayLang = langManager.get_language(substituteLang(lang)); // Set your preferred language
let displayLang = langManager.get_language(substituteLang(lang));
if (displayLang) {
buffer.set_language(displayLang);
}
const CUSTOM_SCHEME_ID = `custom${theme.value == "dark" ? "" : "-light"}`;
const schemeManager = GtkSource.StyleSchemeManager.get_default();
buffer.set_style_scheme(schemeManager.get_scheme(CUSTOM_SCHEME_ID));
buffer.set_text(content, -1);
@@ -46,6 +47,7 @@ const TextBlock = (content = "") =>
useMarkup: true,
xalign: 0,
wrap: true,
wrap_mode: Pango10.WrapMode.WORD_CHAR,
selectable: true,
label: content
});
@@ -53,6 +55,7 @@ const TextBlock = (content = "") =>
Utils.execAsync(["bash", "-c", `rm -rf ${LATEX_DIR}`])
.then(() => Utils.execAsync(["bash", "-c", `mkdir -p ${LATEX_DIR}`]))
.catch(print);
const Latex = (content = "") => {
const latexViewArea = Box({
// vscroll: 'never',
@@ -193,7 +196,7 @@ const Divider = () =>
class_name: "divider"
});
const MessageContent = (content) => {
export const MessageContent = (content) => {
const contentBox = Box({
vertical: true,
attribute: {
+5 -3
View File
@@ -1,5 +1,4 @@
// Converts from Markdown to Pango. This does not support code blocks.
// For illogical-impulse, code blocks are treated separately, in their own GtkSourceView widgets.
// Partly inherited from https://github.com/ubunatic/md2pango
const monospaceFonts = 'JetBrains Mono NF, JetBrains Mono Nerd Font, JetBrains Mono NL, SpaceMono NF, SpaceMono Nerd Font, monospace';
@@ -28,7 +27,7 @@ const replacements = {
{ name: 'EMPH', re: /\*(\S.*?\S)\*/g, sub: "<i>$1</i>" },
// { name: 'EMPH', re: /_(\S.*?\S)_/g, sub: "<i>$1</i>" },
{ name: 'HEXCOLOR', re: /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/g, sub: '<span bgcolor="#$1" fgcolor="#000000" font_family="' + monospaceFonts + '">#$1</span>' },
{ name: 'INLCODE', re: /(`)([^`]*)(`)/g, sub: '<span font_weight="bold" font_family="' + monospaceFonts + '">$2</span>' },
{ name: 'INLCODE', re: /(`)([^`]*)(`)/g, sub: '<span font_weight="500" font_family="' + monospaceFonts + '">$2</span>' },
// { name: 'UND', re: /(__|\*\*)(\S[\s\S]*?\S)(__|\*\*)/g, sub: "<u>$2</u>" },
],
}
@@ -68,8 +67,11 @@ export const markdownTest = `## Inline formatting
const std::string GREETING="UwU";
int main() { std::cout << GREETING; }
\`\`\`
\`\`\`py
print("Hello world!")
\`\`\`
## LaTeX
\`\`\`latex
\\frac{d}{dx} \\left( \\frac{x-438}{x^2+23x-7} \\right) = \\frac{-x^2 + 869}{(x^2+23x-7)^2} \\\\ → \\\\ cos(2x) = 2cos^2(x) - 1 = 1 - 2sin^2(x) = cos^2(x) - sin^2(x)
\`\`\`
`;
`;
+3
View File
@@ -0,0 +1,3 @@
import Gtk from "gi://Gtk?version=3.0";
export const TextView = Widget.subclass<typeof Gtk.TextView, Gtk.TextView.ConstructorProperties>(Gtk.TextView, "AgsTextView");