Skip to content

Commit

Permalink
Merge pull request #7 from JuliaGtk/jw/link
Browse files Browse the repository at this point in the history
show links, allow setting GObject properties of the TextView in the constructor
  • Loading branch information
jonathanBieler committed Dec 15, 2023
2 parents 11052a0 + 2b4c6ec commit 3efb293
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GtkMarkdownTextView"
uuid = "26d59822-f2b6-4a0d-bae1-4d8fc12fd86b"
version = "0.2.0"
version = "0.2.1"

[deps]
Gtk4 = "9db2cae5-386f-4011-9d63-a5602296539b"
Expand All @@ -9,6 +9,7 @@ Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
[compat]
Gtk4 = "0.5, 0.6"
julia = "1.6"
Markdown = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
19 changes: 15 additions & 4 deletions src/GtkMarkdownTextView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ module GtkMarkdownTextView
view::GtkTextView
buffer::GtkTextBuffer

function MarkdownTextView(m::Markdown.MD, prelude::String, mc::MarkdownColors = MarkdownColors())
function MarkdownTextView(m::Markdown.MD, prelude::String, mc::MarkdownColors = MarkdownColors(); kwargs...)

buffer = GtkTextBuffer()
buffer.text = prelude
view = GtkTextView(buffer)
view = GtkTextView(buffer; kwargs...)

style_css(view,
"window, view, textview, buffer, text {
Expand Down Expand Up @@ -111,8 +111,6 @@ module GtkMarkdownTextView
end

function insert_MD!(buffer, m::Markdown.Paragraph, i)
# insert!(buffer, "\n\n")
# i += 2
for el in m.content
i = insert_MD!(buffer, el, i)
end
Expand Down Expand Up @@ -151,6 +149,17 @@ module GtkMarkdownTextView
tag(buffer, tagname(m), ip, i)
i
end

function insert_MD!(buffer, m::Markdown.Link, i)
for el in m.text
i = insert_MD!(buffer, el, i)
end
insert!(buffer, "(")
i += 1
i = insert_MD!(buffer, m.url, i)
insert!(buffer, ")")
i += 1
end

function insert_MD!(buffer, m, i)
if isdefined(m, :text)
Expand All @@ -161,6 +170,8 @@ module GtkMarkdownTextView
if isdefined(m, :content)
for el in m.content
i = insert_MD!(buffer, el, i)
insert!(buffer, "\n\n")
i += 2
end
end
i
Expand Down

0 comments on commit 3efb293

Please sign in to comment.