From 3d4c629ac293711074ac5a692b58db32f9c8bbc9 Mon Sep 17 00:00:00 2001 From: Nick White Date: Sun, 16 Mar 2014 14:08:25 -0400 Subject: Improve image link parsing, and remove links completely for now --- tkread | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tkread b/tkread index 126156f..30639ce 100755 --- a/tkread +++ b/tkread @@ -123,13 +123,40 @@ proc markup {widget} { if [file exists $localfile] { set curimg [image create photo -file $localfile] $widget image create $insertion -image $curimg + set cur $insertion } else { - $widget insert [indexmovechar $insertion "- 2"] $alt + $widget insert $insertion $alt + set cur [indexmovechar $insertion "+ [string length $alt]"] } set cur [$widget search {![} $cur end] } + # remove links + # TODO: save the link contents and allow the links to be shown / hidden with a keystroke + set cur [$widget search {[} 0.0 end] + while {$cur != ""} { + set altstart [indexmovechar $cur "+ 1"] + set cur [$widget search "](" $cur end] + if {$cur == ""} { break } + set altend $cur + set srcstart [indexmovechar $cur "+ 1"] + set cur [$widget search ")" $cur end] + if {$cur == ""} { break } + set srcend $cur + + set alt [$widget get $altstart $altend] + set src [$widget get $srcstart $srcend] + + $widget delete [indexmovechar $altstart "- 1"] [indexmovechar $srcend "+ 1"] + set insertion [indexmovechar $altstart "- 1"] + $widget insert $insertion $alt + + set cur [indexmovechar $insertion "+ [string length $alt]"] + set cur [$widget search {[} $cur end] + } + + # process underlined headings foreach fmt $underlinefmt { set searchchar [lindex $fmt 0] -- cgit v1.2.3