summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2014-02-22 17:10:32 +0000
committerNick White <git@njw.me.uk>2014-02-22 17:10:32 +0000
commitf39abeb1a9b048713d8de2670523c4d1fe687888 (patch)
treed0d1805dad47c733d6d8f3fc4ce744635f772d81
parentef3c9334483f1796ac3053794120f359f7676a1d (diff)
downloadtkread-f39abeb1a9b048713d8de2670523c4d1fe687888.tar.bz2
tkread-f39abeb1a9b048713d8de2670523c4d1fe687888.zip
Add underline heading processing
-rwxr-xr-xtkread47
1 files changed, 40 insertions, 7 deletions
diff --git a/tkread b/tkread
index af9a9e9..95f5d42 100755
--- a/tkread
+++ b/tkread
@@ -35,17 +35,20 @@ set invertoutercolour #222222
set inverted 0
set drag 0
set tagnum 0
+set underlinenum 0
set domarkdown 0
set surroundfmt { \
{"***" "0" "bold italic"} \
{"**" "0" "bold"} \
{"*" "0" "italic"} \
- {"===" "0" "italic"} \
- {"==" "3" "italic"} \
- {"=" "6" ""} \
}
+set underlinefmt { \
+ {"=" "6" ""} \
+ {"-" "3" "italic"} \
+}
+
if { $::argc > 0 && [lindex $::argv 0] == "-h" } {
puts "Usage: $usage"
exit
@@ -70,16 +73,20 @@ proc indexmovechar {str moveby} {
return $linenum.[expr $charnum $moveby]
}
-# This uses marks before tags, as they handle deletions fine, so
-# marks can be made and then the formatting characters can be
-# deleted without affecting the position for formatting.
+# TODO: move each section into their own procedures
proc markup {widget} {
global surroundfmt
+ global underlinefmt
global fontfamily
global fontsize
global tagnum
+ global underlinenum
# process surrounds (bold, italic, and some headers)
+ # This uses marks before tags, as they handle deletions fine, so
+ # marks can be made and then the formatting characters can be
+ # deleted without affecting the position for formatting
+ # (should try just tags as they may still work).
foreach fmt $surroundfmt {
set searchchar [lindex $fmt 0]
set fmtsizemod [lindex $fmt 1]
@@ -115,7 +122,6 @@ proc markup {widget} {
$widget tag add tag_$tagnum markon_$x markoff_$x
}
- # TODO: change in changeFontSize too if this works
$widget tag configure tag_$tagnum -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring"
incr tagnum
}
@@ -147,6 +153,26 @@ proc markup {widget} {
set cur [$widget search {![} $cur end]
}
+
+ # NOTE: rewrap currently messes with this
+ # process underlined headings
+ foreach fmt $underlinefmt {
+ set searchchar [lindex $fmt 0]
+ set fmtsizemod [lindex $fmt 1]
+ set fmtstring [lindex $fmt 2]
+
+ set cur [$widget search -regexp "^$searchchar" 0.0 end]
+ while {$cur != ""} {
+ set dotindex [string first . $cur]
+ set linenum [string range $cur 0 [expr $dotindex - 1]]
+ $widget tag add underline_$underlinenum [expr $linenum - 1].0 $linenum.end
+ $widget delete $linenum.0 [expr $linenum + 1].0
+
+ set cur [$widget search -regexp "^$searchchar" [expr $linenum + 1].0 end]
+ }
+ $widget tag configure underline_$underlinenum -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring"
+ incr underlinenum
+ }
}
proc changeFontSize {change} {
@@ -154,6 +180,8 @@ proc changeFontSize {change} {
global fontsize
global surroundfmt
global tagnum
+ global underlinefmt
+ global underlinenum
set newsize [expr $fontsize $change]
if {$newsize > 0} {
set fontsize $newsize
@@ -163,6 +191,11 @@ proc changeFontSize {change} {
set fmtsizemod [lindex [lindex $surroundfmt $x] 1]
.t tag configure tag_$x -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring"
}
+ for {set x 0} {$x < $underlinenum} {incr x} {
+ set fmtstring [lindex [lindex $underlinefmt $x] 2]
+ set fmtsizemod [lindex [lindex $underlinefmt $x] 1]
+ .t tag configure underline_$x -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring"
+ }
}
}