-
Notifications
You must be signed in to change notification settings - Fork 4
Add ability to link to chapter/section #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
To link to a chapter/section: [anchor text](@chapter or section title) This change adds a slot to the weaver to store a map of chapter/section titles to their IDs. Then when we're weaving, we search for these links and replace them with their [anchor text](#c:id). This commit is a work-in-progress that I want to at least get out to start bouncing ideas around.
|
||
--- foobaz | ||
(format nil (* 2 2)) | ||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was using this as a scratch file to play around with in a REPL.
(let* ((file-defs (parse-lit-files '("dev.lit")))
(weaver (make-weaver-default file-defs)))
(add-section weaver '("Some Chapter") "c2")
; ...
)
|
||
(defun weave-prose-line (weaver line def) | ||
(loop for expr in line do | ||
(cond ((stringp expr) (write-string expr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't intend to make this blank space change. I have a habit of running M-q
for paredit-reindent-defun
and saved/committed this and didn't want to bother with undoing it yet.
weave.lisp
Outdated
(replace-sections-with-id-anchors | ||
(weaver-section-map weaver) | ||
expr)) | ||
(write-string expr))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ This is the new bit that is obscured by all of the blank space changes. This along with the comment below are the two core pieces. However it's implemented, these seem like the two most reasonable places to hook in to (1) map section/chapter titles to IDs and (2) replace the link references with their IDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any regex scanning like this should happen in the parser. By the time it gets here it should be a structured command.
For example, all the here is a line with a @{reference}
becomes "here is a line with a " (:INCLUDE "reference")
. So similarly, this should be a command type like (:SECTION-REFERENCE "name")
.
utils.lisp
Outdated
;; | ||
;; I haven't yet gotten close to finishing that implementation. So it | ||
;; doesn't make much sense to have this data structure right now. | ||
;; But oh well. Whatever. It works for an MVP of the chapter/section linking stuff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ Of course that could also be done with simple string matching. I was also thinking this could be useful for something like letting you use [some section](@some section)
if it's unique but [some section](@some chapter:@some-section)
if the section title wasn't unique. (Etc. for @some file name
). Basically... I had a very loosely woven idea that it might be useful and it seemed like a fun way to practice LISP. I don't think it's actually worthwhile for anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had not thought of this idea. I am perfectly open to giving it a try and think its a cool idea. I am also just fine with forcing them to write out the title.
weave.lisp
Outdated
(section-id | ||
(weaver-section-counter weaver) | ||
(weaver-chapter-counter weaver))) | ||
(add-section weaver (list (second expr)) (section-id (weaver-section-counter weaver) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling this out from all the noise. One core piece of this here on line 289 and 298.
This seemed like a good place to hook in and save off the mapping of chapter/section titles to IDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table of contents toc
structure on weaver should have all the information you need. It it will specify what all the chapters and sections are and which files they are in. (Just try printing it out and seeing). I would recommend making a pure function which takes the toc
as input and produces whatever identifier trie you need.
I would also probably put that function in toc.lisp
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table of contents
toc
structure on weaver should have all the information you need.
Ah! That's obvious now.
I have only looked at this briefly. What do you think about the idea of making From my experience there are actually a lot of subtle rules about how markdown is expanded (likely there are edge cases), and a lot of the complexity here seems to be parsing those links. |
I think I like that. Keeps a clear separation between what's weave and what's markdown. Rather than As for syntax, I like the idea of keeping parity with the code blocks by re-using the same So |
@eihli great! Let me take an in-depth look tonight and give you more appropriate feedback. |
weave.lisp
Outdated
;; | ||
;; Right now, it doesn't work across files in a book. | ||
;; Heck... it barely works at all. | ||
(section-map '() :type list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be conscious of multiple files. When a chapter/section is referenced in the same file it should be a relative link (just the anchor portion). When it is referenced in a different file, that file name will be prepended to the anchor. See how block reference anchors are produced.
My comments are probably hard to read out of order, so here is a summary:
|
Thinking out loud. There is a slight inconsistency in our proposed syntax. Perhaps |
Excited to see where this goes. Just following up to see if you need anything from me. |
No questions or anything yet. Just haven't had much free time lately. |
Detect # vs ## and use the list (:ANCHOR (:C "Ch Title")) or (:ANCHOR (:S "Section Title")) depending on which.
10fb425
to
768a5b6
Compare
Just a status update as of commit cb4e960. Most of the diff is either space changes that can be ignored or comment blocks with scratch code that helped me explore. There's only a few lines of new code. I've been using This And then the Not great yet. Can't provide link text for the anchor that's different from the chapter/section name that you're linking to. But getting there. I've been using some scratch files to test/iterate. Will update the tests once things settle down.
|
Really excited! I will review this in detail soon. |
@eihli Just letting you know I had another personal delay. As an aside, I tried to find your contact information on your site. If you are interested in providing that feel free to send me an email (on my github page). |
To link to a chapter/section:
[anchor text](@chapter or section title)
This change adds a slot to the weaver to store a map of chapter/section titles to their IDs.
Then when we're weaving, we search for these links and replace them with their anchor text.
This commit is a work-in-progress that I want to at least get out to start bouncing ideas around.