Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the
aihistpart of AnswerDotAI/mdhtml#98, replacing #9 and #11 (and replacing AnswerDotAI/aidialog#71 and AnswerDotAI/aidialog#72, sinceaidialogno longer needs to change).Previously
dlg2mdunpacked cells, replies, outputs, and attachments only to flatten them straight into one Markdown string, so things like octavo or solveit sharing that needed cell boundaries or metadata had to re-parse that Markdown or rebuild something similar. This PR exposes the structured cell list directly and turnsdlg2mdinto a thin join over it.The idea is to keep
aihistfocused on extracting what's in the notebook and leave filtering and presentation to callers.Implementation details and design decisions (AI-written)
Structured cell projection (
src/export.rs)export_nb(nb, opts)andexport_cell(nb, cell, language, weave)are now public and re-exported fromsrc/lib.rsunder thefullfeature:ExportOptsacceptslanguage(None),exportfilter(false),weave(false),frontmatter(true), andatt_data(true).ExportDocreturnsfrontmatter, resolvedlanguage(opts.language, thenmetadata.kernelspec.language, thenmetadata.language_info.name, defaulting to"python"), andcells.ExportCellholdsid,kind,src,out,attachments, and full cellmeta. Emptycodecells are skipped (export_cellreturnsNone).attachment:references remain intact insrcandoutwhile cell attachments populateattachments(with base64 whitespace stripped, anddataomitted whenatt_dataisfalse).ExportPartserializes with a lowercasetypetag acrossmd,code,text,html(with optionaltext),image(with optionaltext),tool, andusage.When
frontmatteris enabled,export_nbextracts leading YAML frontmatter from cell 0 if it is arawornotecell starting with---, terminated by---or..., and containing at least one YAML key-value line. Frontmatter is normalized to end with\nand extracted beforeexportfilterruns. Any Markdown after the closing delimiter in anotecell stays as cell 0.Typed output and reply parts (
src/output.rs,src/reply.rs)output_parts(outputs, html1st)exposesOutputPart(Text,Md,Html,Image) under#[cfg(feature = "full")].merge_streamsmerges only consecutivestdout,stderr, ormarkdownstream entries so streams interleaved withdisplay_dataorexecute_resultpreserve notebook order.HtmlandImageretain ANSI-strippedtext/plainintext.render_mdnow formats overoutput_parts.reply_parts(s)exposesReplyPart(Md,Tool,Usage), keeping invalid JSON fences insideMd. Module layering remains bottom-up:output.rsandreply.rsdo not importexport.rs.Flat Markdown joins and attachment inlining
dlg2md_nbandmsg2md_injoin the output ofexport_nbandexport_cellthroughparts_to_mdandcell_to_md.inline_attsreplacesattachment:references longest-name-first for both raw and percent-encoded names, avoiding prefix collisions such asa.pngmatching insidea.png2.Python bindings (
py/src/lib.rs,python/aihist/hist.py)py/src/lib.rsexposesexport_nb(nb, opts="{}"), andaihist.histexportsexport_dlg(d, *, exportfilter=False, weave=False, language=None, frontmatter=True, att_data=True)._nb(d)now accepts raw notebookdicts directly alongsideDialogobjects and message iterables, soexport_dlganddlg2mdwork without wrapping dicts inaidialog.Compatibility and dependencies
Adds no new Rust or Python dependencies and leaves
aidialogunchanged. Building with--no-default-featureskeepsserdederives out of the minimal build used byjupygate.Python
dlg2mdkeepslanguage='python'by default; passinglanguage=Noneopts into kernelspec inference. A leadingrawYAML frontmatter cell now renders as bare frontmatter indlg2md_nbrather than a fenced raw block and survivesexportfilter=True.Companion PRs: mdhtml PR, draft octavo PR.
Documentation and validation
Updated
README.mdandDEV.md, and added tests intests/aihist.rsandtests/test_hist.pycovering typed parts,att_data,meta, HTML and imagetextfallbacks, language inference,exportfilter,frontmatter=False, interleaved stream ordering, longest-first attachment inlining, and rawdictinput.cargo check --no-default-featuresandcargo test --no-default-features: 5 passed.cargo clippy --workspace --all-targets: 0 new warnings.cargo developandcargo test: 5 passed.pytest -q: 12 passed.