Skip to content

Commit

Permalink
Fix inline code problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemken committed Jun 21, 2018
1 parent ef0617b commit df0447b
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ SUPPORT: [email protected]
HELP: After installation, type

. help stmd2dyn
. help stmd2html
. help stmd

FILES:

stmd.ado
stmd.sthlp
stmd2dyn.ado
stmd2dyn.sthlp
stmd2html.ado
stmd2html.sthlp
18 changes: 18 additions & 0 deletions _dd_do.mata
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
capture mata: mata drop _dd_do()
mata: string colvector function _dd_do(real matrix fenceinfo, real matrix tagmatch) {
dotags = J(rows(fenceinfo),1,"")
for (i=1; i<=rows(fenceinfo); i++) {
if (fenceinfo[i,2]==1) {
if (sum(tagmatch[i,.])==0) dotags[i,1]=("<<dd_do>>")
else if (tagmatch[i,3]==1) {
if (tagmatch[i,4]==0) dotags[i,1]=("<<dd_do: nocommands>>")
else if (tagmatch[i,4]==1) dotags[i,1]=("<<dd_do: quietly>>")
}
else if (tagmatch[i,3]==0 & tagmatch[i,4]==1) dotags[i,1]=("<<dd_do: nooutput>>")
else if (tagmatch[i,5]==1) dotags[i,1]=("<<dd_do: noprompt>>")
}
else if (fenceinfo[i,2]==-1) dotags[i,1]=("<</dd_do>>")
else dotags[i,1]=("")
}
return(dotags)
}
66 changes: 66 additions & 0 deletions _fence_info.mata
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
capture mata: mata drop _fence_info()
mata:
real matrix function _fence_info(string colvector X) {
codefence = "^( ? ? ?)(```+|~~~+)([ ]*)$"
infofence = "^( ? ? ?)(```+|~~~+)\{?s(tata)?\/?(,.*)?\}?$"
fence = ustrregexm(X, codefence)
codebegin = ustrregexm(X, infofence)
fence = fence + codebegin
prespace = J(rows(X),1,.)
cbdepth = J(rows(X),1,0)
fencel = J(rows(X),7,.)
doblock = 0
//cbflen = 0
for (i=1; i<=rows(X); i++) {
// check out the fence
if (i>=2) {
cbdepth[i]=cbdepth[i-1]
fencel[i,.]=fencel[i-1,.]
}
if (ustrregexm(X[i,1], infofence) | ustrregexm(X[i,1], codefence)) {
//X[i,1]
if (ustrregexm(X[i,1], infofence)) {
prespace[i] = ustrlen(ustrregexs(1))
fl = ustrlen(ustrregexs(2))
}
else if (ustrregexm(X[i,1], codefence)) {
prespace[i] = ustrlen(ustrregexs(1))
fl = ustrlen(ustrregexs(2))
}
//fl
// doable?
if (cbdepth[i]==0 & ustrregexm(X[i,1], infofence)) {
cbdepth[i]=cbdepth[i]+1
fencel[i, cbdepth[i]] = fl
codebegin[i] = 1 // redundant
doblock = 1
//cbflen = fencel[i]
}
// not doable: deeper?
else if (ustrregexm(X[i,1], infofence) | cbdepth[i]==0) {
cbdepth[i]=cbdepth[i]+1
fencel[i, cbdepth[i]] = fl
codebegin[i] = 0 // redundant
}
// also deeper
else if (fl < fencel[i, cbdepth[i]]) {
cbdepth[i]=cbdepth[i]+1
fencel[i, cbdepth[i]] = fl
}
else {
fencel[i, cbdepth[i]] = .
cbdepth[i] = cbdepth[i]-1
}
// is this the end of doable?
if (cbdepth[i]==0 & doblock) {
codebegin[i] = -1
doblock=0
}
}
//X[i,1]
}
return(fence,codebegin,cbdepth,prespace,fencel)
}
end
2 changes: 1 addition & 1 deletion stmd2dyn.ado
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ string colvector function _stitch(string colvector X,
string colvector function _inline_code(string colvector X, real colvector cbdepth) {
for (i=1; i<=rows(X); i++) {
if (cbdepth[i] == 0) {
dispdir = ustrregexm(X[i,1], "(`|~)\{?s(tata)?(.*)(`)")
dispdir = ustrregexm(X[i,1], "(`|~)\{?s(tata)?( )+(.*)(`)")
while (dispdir) {
X[i,1] = ustrregexra(X[i,1], "(`|~)\{?s(tata)?\}?", "<<dd_display: ")
X[i,1] = ustrregexra(X[i,1], "`", ">>")
Expand Down
13 changes: 13 additions & 0 deletions update stmd install.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
* Check for previous installation
ado dir stmd
ado uninstall stmd
* If there are more than one previous installation,
* you have to remove them by [number] rather than name

* The actual installation
net from https://www.ssc.wisc.edu/~hemken/Stataworkshops/
net install stmd, replace

* Check
which stmd
which stmd2dyn
5 changes: 0 additions & 5 deletions update stmd2dyn.do

This file was deleted.

0 comments on commit df0447b

Please sign in to comment.