diff options
| author | Nick White <git@njw.me.uk> | 2014-02-23 11:28:24 +0000 | 
|---|---|---|
| committer | Nick White <git@njw.me.uk> | 2014-02-23 11:28:24 +0000 | 
| commit | 7acc178c023b578a6334253e0bc8eef41ab9ef2b (patch) | |
| tree | 19feac63ede93b3313e1cd15512bfdb6c3e9031e | |
| parent | 9cd3319b6f55560ae214c7e1432758fb411156be (diff) | |
| download | tkread-7acc178c023b578a6334253e0bc8eef41ab9ef2b.tar.bz2 tkread-7acc178c023b578a6334253e0bc8eef41ab9ef2b.zip | |
Move surround processing to the end so it doesn't interfere with other parts
| -rwxr-xr-x | tkread | 91 | 
1 files changed, 46 insertions, 45 deletions
| @@ -15,6 +15,7 @@ set usage {tkread [-w] [-m]  # <https://github.com/Gottox/smu>   #  # TODO: +# - rewrap after markdown processing (or just rewrap more smartly), so that things like underlines aren't screwed up by it  # - justify text (not simple; see http://wiki.tcl.tk/1774)  # - add a basic search function  # - add function to type 30g to scroll 30% through an article @@ -97,50 +98,6 @@ proc markup {widget} {  	global underlinenum  	global prefixnum -	# 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] -		set fmtstring [lindex $fmt 2] -		set searchlen [string length $searchchar] -		set insection 0 -		set cur "" -		set markonnum 0 -		set markoffnum 0 - -		set cur [$widget search $searchchar 0.0 end] -		while {$cur != ""} { -			if {$insection == 0} { -				set insection 1 -				$widget mark set markon_$markonnum $cur -				incr markonnum -			} else { -				set insection 0 -				$widget mark set markoff_$markoffnum $cur -				incr markoffnum -			} -			$widget delete $cur "$cur + $searchlen chars" - -			set cur [$widget search "$searchchar" $cur end] -		} - -		# ignore any final mismatched mark -		if {$markonnum != $markoffnum } { -			set markonnum $markoffnum -		} - -		for {set x 0} {$x < $markonnum} {incr x} { -			$widget tag add tag_$tagnum markon_$x markoff_$x -		} - -		$widget tag configure tag_$tagnum -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring" -		incr tagnum -	} -  	# process images  	set cur [$widget search {![} 0.0 end]  	while {$cur != ""} { @@ -169,7 +126,6 @@ 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] @@ -189,6 +145,7 @@ proc markup {widget} {  		incr underlinenum  	} +	# process line prefixes  	foreach fmt $prefixfmt {  		set searchchar [lindex $fmt 0]  		set fmtsizemod [lindex $fmt 1] @@ -206,6 +163,50 @@ proc markup {widget} {  		$widget tag configure prefix_$prefixnum -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring"  		incr prefixnum  	} + +	# 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] +		set fmtstring [lindex $fmt 2] +		set searchlen [string length $searchchar] +		set insection 0 +		set cur "" +		set markonnum 0 +		set markoffnum 0 + +		set cur [$widget search $searchchar 0.0 end] +		while {$cur != ""} { +			if {$insection == 0} { +				set insection 1 +				$widget mark set markon_$markonnum $cur +				incr markonnum +			} else { +				set insection 0 +				$widget mark set markoff_$markoffnum $cur +				incr markoffnum +			} +			$widget delete $cur "$cur + $searchlen chars" + +			set cur [$widget search "$searchchar" $cur end] +		} + +		# ignore any final mismatched mark +		if {$markonnum != $markoffnum } { +			set markonnum $markoffnum +		} + +		for {set x 0} {$x < $markonnum} {incr x} { +			$widget tag add tag_$tagnum markon_$x markoff_$x +		} + +		$widget tag configure tag_$tagnum -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring" +		incr tagnum +	}  }  proc changeFontSize {change} { | 
