Skip to content
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

Make DOMParser and ZU.walkNodeDom available in background export #2094

Closed
yangfurong opened this issue Mar 30, 2022 · 57 comments
Closed

Make DOMParser and ZU.walkNodeDom available in background export #2094

yangfurong opened this issue Mar 30, 2022 · 57 comments

Comments

@yangfurong
Copy link

yangfurong commented Mar 30, 2022

Log ID: DMMHCUW6-refs-euc

Hi.

In Zotero 5.0, I used Zotfile to generate notes from annotations in PDF files. In those notes, Zotfile used to explicitly include Zotero-URI links pointing to the positions where the corresponding annotations were taken. Thus, when I exported some Zotero items to a Bibtex file, the Bibtex items included a "note" field where the Zotero-URI links were also included. An example is shown below.

@techreport{cheng-iccrg-delivery-rate-estimation-00,
  type = {Internet-Draft},
  title = {Delivery Rate Estimation},
  author = {Cheng, Yuchung and Cardwell, Neal and Yeganeh, Soheil Hassas and Jacobson, Van},
  year = {2017},
  month = jul,
  number = {draft-cheng-iccrg-delivery-rate-estimation-00},
  institution = {{Internet Engineering Task Force / Internet Engineering Task Force}},
  pagetotal = {16},
  note = {\textbf{Extracted Annotations (2020/4/20 上午11:40:06)}
\par
"Each acknowledgment that cumulatively or selectively acknowledges that the network has delivered new data produces a rate sample which records the amount of data delivered over the time interval between the transmission of a data packet and the acknowledgment of that packet." (\href{zotero://open-pdf/library/items/Q2AEBDT5?page=3}{ :3})}
}

However, in Zotero 6.0, Zotfile's "Extract Annotations" is replaced by the Zotero built-in function "Add Note From Annotations". Unlike the notes generated by Zotfile, the new-style notes do not explicitly include Zotero-URI links. Instead, they use embedded links. Therefore, if we export a Zotero item with a new-style note to a Bibtex file, we have no more Zotero-URI links in the note field of the Bibtex item. An example is given below.

@article{huang_IndepthStudyLTE_2013,
  title = {An In-Depth Study of {{LTE}}: Effect of Network Protocol and Application Behavior on Performance},
  shorttitle = {An In-Depth Study of {{LTE}}},
  author = {Huang, Junxian and Qian, Feng and Guo, Yihua and Zhou, Yuanyuan and Xu, Qiang and Mao, Z. Morley and Sen, Subhabrata and Spatscheck, Oliver},
  year = {2013},
  month = sep,
  journal = {ACM SIGCOMM Computer Communication Review},
  volume = {43},
  number = {4},
  pages = {363--374},
  note = {\section{Annotations\\
(3/30/2022, 3:22:46 PM)}

\par
``However, the interactions among applications, network transport protocol, and the radio layer still remain unexplored.'' (Huang et al., 2013, p. 363)}
}

But, as discussed in the Zotero forum (https://forums.zotero.org/discussion/95285/pdf-annotations-do-not-include-markdown-links#latest), Zotero 6.0 is able to export a new-style note to a markdown file that includes Zotero-URI links.

# Annotations  
(3/30/2022, 3:22:46 PM)

“However, the interactions among applications, network transport protocol, and the radio layer still remain unexplored.” ([Huang et al., 2013, p. 363](zotero://select/library/items/L2KWDK96)) ([pdf](zotero://open-pdf/library/items/8SU8CCQA?page=1&annotation=EZFZEMQV))

As @dstillman mentioned, in Zotero 6.0,

All the information used to form the links in the built-in Markdown export is available in the source of the notes, and plugins can use it as they wish.

So, I guess that BBT currently does not decode the notes in the same way as Zotero 6.0's "Markdown export".

To verify this, I wrote a postscript in BBT to print the decoded notes in Zotero's debug console. The script and output are shown below.

if (Translator.BetterBibTeX) {
Zotero.debug(item.notes)
reference.add({name: 'test', value: item.notes[0]["note"], html: true})
}
[ "0": { "key": "P84FUWMN" "version": 4687 "itemType": "note" "parentItem": "WZWK7RUK" "note": "<div data-citation-items=\"%5B%7B%22uris%22%3A%5B%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FWZWK7RUK%22%5D%2C%22itemData%22%3A%7B%22id%22%3A%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FWZWK7RUK%22%2C%22type%22%3A%22paper-conference%22%2C%22abstract%22%3A%22TCP%20has%20been%20the%20dominant%20transport%20protocol%20for%20mobile%20internet%20since%20its%20origin.%20Its%20behaviors%20play%20an%20essential%20role%20in%20determining%20quality%20of%20service%2Fexperience%20(QoS%20and%20QoE)%20for%20mobile%20apps.%20While%20TCP%20has%20been%20extensively%20studied%20in%20a%20static%2C%20walking%2C%20or%20driving%20mobility%2C%20it%20has%20not%20been%20well%20explored%20in%20highspeed%20(%3E%20200%20km%2Fh)%20mobility%20cases.%20With%20increasing%20investment%20and%20deployment%20of%20high%20speed%20rails%20(HSRs)%2C%20a%20critical%20demand%20of%20understanding%20TCP%20performance%20under%20extremely%20high-speed%20mobility%20arises.%20In%20this%20paper%2C%20we%20conduct%20an%20in-depth%20study%20to%20investigate%20TCP%20behaviors%20on%20HSR.%20We%20collect%2090%20GB%20of%20measurement%20data%20on%20HSPA%2B%20networks%20in%20Chinese%20high-speed%20trains%20with%20a%20peak%20speed%20of%20310%20km%2Fh%2C%20along%20various%20routes%20(covering%205%2C000%20km)%20during%20an%208-month%20period.%20We%20analyze%20the%20impacts%20of%20high-speed%20mobility%20and%20handoff%20on%20performance%20metrics%20including%20RTT%2C%20packet%20loss%20and%20network%20disconnection.%20Then%20we%20demystify%20the%20grand%20challenges%20posed%20on%20TCP%20operations%20(TCP%20establishment%2C%20transmission%2C%20congestion%20control%20and%20termination).%20Our%20study%20shows%20that%20performance%20greatly%20declines%20in%20HSR%2C%20where%20RTT%20spikes%2C%20packet%20drops%20and%20network%20disconnections%20are%20more%20signi%EF%AC%81cant%20and%20occur%20more%20frequently%2C%20compared%20with%20static%2C%20slowly%20moving%20or%20driving%20mobility%20cases.%20Moreover%2C%20TCP%20fails%20to%20adapt%20well%20to%20such%20extremely%20high-speed%20and%20yields%20severely%20abnormal%20behaviors%2C%20such%20as%20high%20spurious%20RTO%20rate%2C%20aggressive%20congestion%20window%20reduction%2C%20long%20delay%20of%20connection%20establishment%20and%20closure%2C%20and%20transmission%20interruption.%20All%20these%20%EF%AC%81ndings%20indicate%20that%20extremely%20high-speed%20indeed%20poses%20a%20big%20threat%20to%20today%E2%80%99s%20TCP%20and%20it%20calls%20for%20urgent%20efforts%20to%20develop%20HSR-friendly%20protocols%20and%20wireless%20networks%20to%20address%20even%20more%20complicated%20challenges%20raised%20by%20faster%20trains%2Faircrafts%20in%20the%20foreseeable%20future.%22%2C%22container-title%22%3A%222015%20IEEE%20Conference%20on%20Computer%20Communications%20(INFOCOM)%22%2C%22DOI%22%3A%2210.1109%2FINFOCOM.2015.7218665%22%2C%22event%22%3A%22IEEE%20INFOCOM%202015%20-%20IEEE%20Conference%20on%20Computer%20Communications%22%2C%22event-place%22%3A%22Kowloon%2C%20Hong%20Kong%22%2C%22ISBN%22%3A%22978-1-4799-8381-0%22%2C%22language%22%3A%22en%22%2C%22page%22%3A%222731-2739%22%2C%22publisher%22%3A%22IEEE%22%2C%22publisher-place%22%3A%22Kowloon%2C%20Hong%20Kong%22%2C%22source%22%3A%22DOI.org%20(Crossref)%22%2C%22title%22%3A%22A%20measurement%20study%20on%20TCP%20behaviors%20in%20HSPA%26%23x002B%3B%20networks%20on%20high-speed%20rails%22%2C%22URL%22%3A%22http%3A%2F%2Fieeexplore.ieee.org%2Fdocument%2F7218665%2F%22%2C%22author%22%3A%5B%7B%22family%22%3A%22Li%22%2C%22given%22%3A%22Li%22%7D%2C%7B%22family%22%3A%22Xu%22%2C%22given%22%3A%22Ke%22%7D%2C%7B%22family%22%3A%22Wang%22%2C%22given%22%3A%22Dan%22%7D%2C%7B%22family%22%3A%22Peng%22%2C%22given%22%3A%22Chunyi%22%7D%2C%7B%22family%22%3A%22Xiao%22%2C%22given%22%3A%22Qingyang%22%7D%2C%7B%22family%22%3A%22Mijumbi%22%2C%22given%22%3A%22Rashid%22%7D%5D%2C%22accessed%22%3A%7B%22date-parts%22%3A%5B%5B%222020%22%2C4%2C29%5D%5D%7D%2C%22issued%22%3A%7B%22date-parts%22%3A%5B%5B%222015%22%2C4%5D%5D%7D%2C%22citation-key%22%3A%22li_MeasurementStudyTCP_2015%22%7D%7D%5D\" data-schema-version=\"6\"><h1>Annotations<br>(3/22/2022, 5:09:25 PM)</h1>\n<p><span class=\"highlight\" data-annotation=\"%7B%22attachmentURI%22%3A%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FG8YEGCWI%22%2C%22annotationKey%22%3A%222SA9QVEC%22%2C%22color%22%3A%22%23ffd400%22%2C%22pageLabel%22%3A%222731%22%2C%22position%22%3A%7B%22pageIndex%22%3A0%2C%22rects%22%3A%5B%5B95.856%2C515.672%2C300.021%2C523.777%5D%2C%5B46.01%2C505.712%2C300.017%2C513.611%5D%2C%5B46.01%2C495.742%2C300.017%2C503.641%5D%2C%5B46.01%2C485.782%2C95.287%2C493.681%5D%5D%7D%2C%22citationItem%22%3A%7B%22uris%22%3A%5B%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FWZWK7RUK%22%5D%2C%22locator%22%3A%222731%22%7D%7D\"><span style=\"background-color: #ffd40080\">“TCP has been the dominant transport protocol for mobile internet since its origin. Its behaviors play an essential role in determining quality of service/experience (QoS and QoE) for mobile apps.”</span></span> <span class=\"citation\" data-citation=\"%7B%22citationItems%22%3A%5B%7B%22uris%22%3A%5B%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FWZWK7RUK%22%5D%2C%22locator%22%3A%222731%22%7D%5D%2C%22properties%22%3A%7B%7D%7D\">(<span class=\"citation-item\">Li et al., 2015, p. 2731</span>)</span> This is a note</p>\n</div>" "tags": [] "relations": {} "dateAdded": "2022-03-22T09:09:25Z" "dateModified": "2022-03-22T09:09:34Z" "uri": "http://zotero.org/users/4752161/items/P84FUWMN" } ]

The output may be a bit messy. But, if we translate it to HTML format, it looks like this.

[ "0": { "key": "P84FUWMN" "version": 4687 "itemType": "note" "parentItem": "WZWK7RUK" "note": "
Annotations
(3/22/2022, 5:09:25 PM)
\n
“TCP has been the dominant transport protocol for mobile internet since its origin. Its behaviors play an essential role in determining quality of service/experience (QoS and QoE) for mobile apps.” (Li et al., 2015, p. 2731) This is a note

\n
" "tags": [] "relations": {} "dateAdded": "2022-03-22T09:09:25Z" "dateModified": "2022-03-22T09:09:34Z" "uri": "http://zotero.org/users/4752161/items/P84FUWMN" } ]

So, I would like to ask if it is possible to change BBT's way of decoding notes in order to include Zotero-URI links in the note field of Bibtex items? Thanks a lot.

@github-actions
Copy link

It looks like you did not upload an support log. The support log is important; it gives @retorquere your current BBT settings and a copy of the items under consideration as a test case so he can best replicate your issue, or build towards the desired behavior. Without it, @retorquere is effectively blind. Support logs are useful for both analysis and for enhancement requests; in the case of export enhancements, I need the copy of the references you have in mind.

If you did try to submit a support log, but the ID looked like D<number>, that is a Zotero debug report, which I cannot access. Please re-submit a BBT debug log by one of the methods below.

This request is much more likely than not to apply to you too @yangfurong, even if you think it unlikely. Please trust @retorquere when he says he will usually need one; he will more often than not just end up saying "please send a debug log". Let's just skip over the unnecesary delay this entails. Sending a debug log is very easy:

  1. If your issue relates to how BBT behaves around a specific reference(s), such as citekey generation or export, select at least one of the items(s) under consideration, right-click it, and submit an BBT support log from that popup menu. If the problem is with export, please do include a sample of what you see exported, and what you expected to see exported for these references.

  2. If the issue does not relate to references and is of a more general nature, generate an support log by restarting Zotero with debugging enabled (Help -> Debug Output Logging -> Restart with logging enabled), reproducing your problem, and selecting "Send Better BibTeX debug report..." from the help menu.

Once done, you will see a debug ID in red. Please post that debug id in the issue here.

Thank you!

@retorquere
Copy link
Owner

retorquere commented Mar 31, 2022

So, I guess that BBT currently does not decode the notes in the same way as Zotero 6.0's "Markdown export".

I don't think that is the problem. It looks like the URL is available as metadata to the annotation, and that what Dan is saying is "if you want to use that metadata to add the URL to the exported annotation, you can". I've looked at MMHCUW6-refs-euc and there is enough information to create the URL, but it's outside the note.

If this is correct, I don't think it is within the scope of BBT to modify the annotation during export. It should be possible using a postscript, and we can look into that, but maybe the Zotfile author can be persuaded to patch the note-export to once again include the URI. It seems more within the scope of Zotfile.

@dstillman
Copy link

dstillman commented Mar 31, 2022

@retorquere: Not sure what you mean there. ZotFile no longer does annotation extraction and doesn't do anything with export. [Edit: I guess you mean monkey-patch? No. ZotFile is no longer maintained and shouldn't be taking on more functionality.]

What are you saying is outside the note?

@retorquere
Copy link
Owner

I did mean ZotFile could do a monkey-patch, yes. I didn't know it was unmaintained and it seemed to align more closely with the scope of stuff ZotFile did than anything else.

With "outside the node" I meant "outside the note body". I was attempting to simplify. In the note.note I see:

note.note
<div data-citation-items="[{"uris":["http://zotero.org/users/4752161/items/L2KWDK96"],"itemData":{"id":"http://zotero.org/users/4752161/items/L2KWDK96","type":"article-journal","container-title":"ACM SIGCOMM Computer Communication Review","DOI":"10.1145/2534169.2486006","ISSN":"0146-4833","issue":"4","journalAbbreviation":"SIGCOMM Comput. Commun. Rev.","language":"en","page":"363-374","source":"DOI.org (Crossref)","title":"An in-depth study of LTE: effect of network protocol and application behavior on performance","title-short":"An in-depth study of LTE","URL":"https://dl.acm.org/doi/10.1145/2534169.2486006","volume":"43","author":[{"family":"Huang","given":"Junxian"},{"family":"Qian","given":"Feng"},{"family":"Guo","given":"Yihua"},{"family":"Zhou","given":"Yuanyuan"},{"family":"Xu","given":"Qiang"},{"family":"Mao","given":"Z. Morley"},{"family":"Sen","given":"Subhabrata"},{"family":"Spatscheck","given":"Oliver"}],"accessed":{"date-parts":[["2021",6,7]]},"issued":{"date-parts":[["2013",9,19]]},"citation-key":"huang_IndepthStudyLTE_2013"}}]" data-schema-version="6">
	<h1>Annotations
		<br/>(3/30/2022, 3:22:46 PM)
	</h1>
	<p>
		<span class="highlight" data-annotation="{"attachmentURI":"http://zotero.org/users/4752161/items/8SU8CCQA","annotationKey":"EZFZEMQV","color":"#ffd400","pageLabel":"363","position":{"pageIndex":0,"rects":[[122.047,534.989,292.894,543.005],[53.798,524.528,292.894,532.544],[53.798,514.067,78.948,522.083]]},"citationItem":{"uris":["http://zotero.org/users/4752161/items/L2KWDK96"],"locator":"363"}}">“However, the interactions among applications, network transport protocol, and the radio layer still remain unexplored.”</span>
		<span class="citation" data-citation="{"citationItems":[{"uris":["http://zotero.org/users/4752161/items/L2KWDK96"],"locator":"363"}],"properties":{}}">(
			<span class="citation-item">Huang et al., 2013, p. 363</span>)
		</span>
	</p>
</div>

which AFAICT doesn't contain the link @yangfurong wants, so it isn't a matter of BBT "decoding the note", it is a matter of injecting the desired information into the note before BBT does a translation to LaTeX. note.uri has http://zotero.org/users/......./items/........ alongside note.note which has the information to re-create the link Zotfile previously exported.

I don't think however it is within BBTs scope to synthesize notes this way. It can likely be done with a postscript, and if @yangfurong wants that I'll help create it. But for a structural solution I do not think BBT should do it.

@yangfurong
Copy link
Author

@retorquere Thanks a lot for your reply. In my use case, It is necessary for me to include the links in the note fields of BibTex items. The reason is that I need to import those notes with links in Obsidian that directly reads the note fields of exported BibTex items. It would be very helpful if you can provide some instructions to implement this function with a postscript.

@retorquere
Copy link
Owner

if (Translator.BetterTeX) {
  if (item.notes) {
    const notes = item.notes.map(note => {
      const [ , kind, lib, key ] = note.uri.match(/^https?:\/\/zotero\.org\/(users|groups)\/((?:local\/)?[^/]+)\/items\/(.+)/)
      const select = (kind === 'users') ? `zotero://select/library/items/${key}` : `zotero://select/groups/${lib}/items/${key}`
      return note.note + ` <a href="${select}">Go to note</a>`
    }).join('</p><p>')

    entry.add({ name: 'note', value: notes, html: true })
  }
}

@yangfurong
Copy link
Author

@retorquere Thank you so much. I have one more question. Could you suggest if it is possible to append another link, which looks like zotero://open-pdf/library/items/8SU8CCQA?page=1&annotation=EZFZEMQV, after the Go to note link? I could do it if I know how to get the attachment ID (8SU8CCQA), the page index of the annotation (1), and the annotation ID (EZFZEMQV). According to your reply above, the note.note content has all the needed data.

@retorquere
Copy link
Owner

It is possible, but more work; you'd have to parse that out of the HTML. The body has

<span class="highlight" data-annotation="<json data>">

which has the attachmentURI, annotationKey and position. Once you have those you could create a select link in the same way as above.

@yangfurong
Copy link
Author

yangfurong commented Apr 1, 2022

Thanks. I will figure out how to do it.
[Edit: BTW, is there any library or APIs that I can use in postscripts for this sake? Or will I have to see a note.note as a string and do everything by myself?]

@retorquere
Copy link
Owner

var doc = new DOMParser().parseFromString(note.note, 'text/html')

will give you a DOM document that you can walk/inspect

@yangfurong
Copy link
Author

var doc = new DOMParser().parseFromString(note.note, 'text/html')

will give you a DOM document that you can walk/inspect

Hi.
I tried this. But it said that "DOMParser is not defined".

{better-bibtex Better BibTeX :error: (worker 35)} +null Entry.postscript failed: <Error: ReferenceError: DOMParser is not defined in resource://zotero-better-bibtex/Better%20BibTeX.js line 121267 > Function line undefined anonymous/result</notes<@resource://zotero-better-bibtex/Better%20BibTeX.js line 121267 > Function:27:11 anonymous/result<@resource://zotero-better-bibtex/Better%20BibTeX.js line 121267 > Function:24:21 anonymous@resource://zotero-better-bibtex/Better%20BibTeX.js line 121267 > Function:12:20 complete@resource://zotero-better-bibtex/Better%20BibTeX.js:137730:17 doExport@resource://zotero-better-bibtex/Better%20BibTeX.js:138513:7 Zotero__workerContext</ctx.onmessage@chrome://zotero-better-bibtex/content/worker/zotero.js?version=6.0.6&platform=win&translator=Better%20BibTeX&output=C%3A%5CUsers%5CFurong%20Yang%5CDesktop%5CExported%20Items.bib&localeDateOrder=mdy&debugEnabled=true&worker=35:67234:11 > 

So, I was trying to find another way and found Zotero.Utilities.
In Zotero.Utilities, there is a function called walkNoteDOM that enables us to walk through the whole note structure and modify some nodes.

/**
	 * Walk the DOM and the contents of JSON data attributes in the HTML representation
	 * of a note, calling visitor functions that might modify it and returning
	 * the resulting HTML.
	 *
	 * Elements are visited in depth-first order. First the element itself is visited,
	 * then its data attributes, then the URIs in its JSON attributes, then its subtree.
	 *
	 * @param {String} note Note HTML
	 * @param {Object} visitors
	 * @param {Function} [visitors.visitContainer]
	 * @param {Function} [visitors.visitAnnotation]
	 * @param {Function} [visitors.visitCitation]
	 * @param {Function} [visitors.visitOtherElement]
	 * @param {Function} [visitors.visitDataAttribute]
	 * @param {Function} [visitors.visitURI] Return a replacement for the passed URI
	 * @return {String} Potentially modified note HTML
	 */
	walkNoteDOM: function (note, visitors) {
		function visit(elem) {
			if (elem.hasAttribute('data-schema-version')) {
				visitors.visitContainer?.(elem);
			}
			else if (elem.hasAttribute('data-annotation')) {
				visitors.visitAnnotation?.(elem);
			}
			else if (elem.hasAttribute('data-citation')) {
				visitors.visitCitation?.(elem);
			}
			else {
				visitors.visitOtherElement?.(elem);
			}

			if (visitors.visitDataAttribute || visitors.visitURI) {
				for (let attr of ['data-citation', 'data-citation-items', 'data-annotation']) {
					if (elem.hasAttribute(attr)) {
						let json;
						try {
							json = JSON.parse(decodeURIComponent(elem.getAttribute(attr)));
						}
						catch (e) {
							continue;
						}

						visitors.visitDataAttribute?.(attr, json);
						if (visitors.visitURI) visitURIs(json);

						elem.setAttribute(attr, JSON.stringify(json));
					}
				}
			}

			for (let child of elem.children) {
				visit(child);
			}
		}

		function visitURIs(json) {
			if (Array.isArray(json)) {
				json.forEach(visitURIs);
			}
			else if (typeof json === 'object') {
				for (let [key, value] of Object.entries(json)) {
					if (key == 'id' || key == 'attachmentURI') {
						json[key] = visitors.visitURI(value);
					}
					else if (key == 'uris') {
						json[key] = value.map(visitors.visitURI)
					}
					else {
						visitURIs(value);
					}
				}
			}
		}

		let wrappedNote = '<div id="note-body">' + note + '</div>';
		let doc;
		if (Zotero.isNode) {
			let { JSDOM } = require('jsdom');
			doc = new JSDOM(wrappedNote).window.document;
		}
		else {
			let parser;
			try {
				parser = new DOMParser();
			}
			catch {
				// Fx60 defines DOMParser but throws an error when you construct
				// it from this context
				parser = Cc['@mozilla.org/xmlextras/domparser;1'].createInstance(Ci.nsIDOMParser);
			}
			doc = parser.parseFromString(wrappedNote, 'text/html');
		}

		let root = doc.getElementById('note-body');
		for (let child of root.children) {
			visit(child);
		}
		return root.innerHTML;
	}

So, I tried to use this function with the script below.

if (Translator.BetterTeX) {
    if (item.notes) {
        var my_visitor = {
            visitContainer: function (obj) {
                Zotero.debug("visitContainer");
            },
            visitAnnotation: function (obj) {
                Zotero.debug("visitAnnotation");
            },
            visitCitation: function (obj) {
                Zotero.debug("visitCitation");
            },
            visitOtherElement: function (obj) {
                Zotero.debug("visitOtherElement");
            },
            visitDataAttribute: function (obj) {
                Zotero.debug("visitDataAttribute");
            },
            visitURI: function (obj) {
                Zotero.debug("visitURI");
                return obj;
            }
        };
        const notes = item.notes.map(note => {
            const [ , kind, lib, key ] = note.uri.match(/^https?:\/\/zotero\.org\/(users|groups)\/((?:local\/)?[^/]+)\/items\/(.+)/);
            const select = (kind === 'users') ? `zotero://select/library/items/${key}` : `zotero://select/groups/${lib}/items/${key}`;
            Zotero.Utilities.walkNoteDOM(note.note, my_visitor);
            return note.note + ` <a href="${select}">Go to note</a>`;
        }).join('</p><p>');
        reference.add({ name: 'note', value: notes, html: true });
    }
}

But, I got a new error.

{better-bibtex Better BibTeX :error: (worker 38)} +null Entry.postscript failed: <Error: TypeError: Zotero.Utilities.walkNoteDOM is not a function in resource://zotero-better-bibtex/Better%20BibTeX.js line 121267 > Function line undefined anonymous/result</notes<@resource://zotero-better-bibtex/Better%20BibTeX.js line 121267 > Function:50:13 anonymous/result<@resource://zotero-better-bibtex/Better%20BibTeX.js line 121267 > Function:45:23 anonymous@resource://zotero-better-bibtex/Better%20BibTeX.js line 121267 > Function:12:20 complete@resource://zotero-better-bibtex/Better%20BibTeX.js:137730:17 doExport@resource://zotero-better-bibtex/Better%20BibTeX.js:138513:7 Zotero__workerContext</ctx.onmessage@chrome://zotero-better-bibtex/content/worker/zotero.js?version=6.0.6&platform=win&translator=Better%20BibTeX&output=C%3A%5CUsers%5CFurong%20Yang%5CDesktop%5CExported%20Items.bib&localeDateOrder=mdy&debugEnabled=true&worker=38:67234:11 > 

I was wondering if Zotero.Utilities is supported in BBT's postscript. So, I checked the code of Better BibteX.ts and found that Zotero.Utilities is also used there with Zotero.Utilities.getCreatorsForType and Zotero.Utilities.text2html. Then, I tried to call the two functions by adding the two lines below in my postscript and it worked!

Zotero.debug(Zotero.Utilities.getCreatorsForType(item.itemType));
Zotero.debug(Zotero.Utilities.text2html(note.note));

The output was like this.

[ "0": "author" "1": "contributor" "2": "editor" "3": "translator" "4": "reviewedAuthor" ]

<p>&lt;div data-citation-items=&quot;%5B%7B%22uris%22%3A%5B%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FL2KWDK96%22%5D%2C%22itemData%22%3A%7B%22id%22%3A%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FL2KWDK96%22%2C%22type%22%3A%22article-journal%22%2C%22container-title%22%3A%22ACM%20SIGCOMM%20Computer%20Communication%20Review%22%2C%22DOI%22%3A%2210.1145%2F2534169.2486006%22%2C%22ISSN%22%3A%220146-4833%22%2C%22issue%22%3A%224%22%2C%22journalAbbreviation%22%3A%22SIGCOMM%20Comput.%20Commun.%20Rev.%22%2C%22language%22%3A%22en%22%2C%22page%22%3A%22363-374%22%2C%22source%22%3A%22DOI.org%20(Crossref)%22%2C%22title%22%3A%22An%20in-depth%20study%20of%20LTE%3A%20effect%20of%20network%20protocol%20and%20application%20behavior%20on%20performance%22%2C%22title-short%22%3A%22An%20in-depth%20study%20of%20LTE%22%2C%22URL%22%3A%22https%3A%2F%2Fdl.acm.org%2Fdoi%2F10.1145%2F2534169.2486006%22%2C%22volume%22%3A%2243%22%2C%22author%22%3A%5B%7B%22family%22%3A%22Huang%22%2C%22given%22%3A%22Junxian%22%7D%2C%7B%22family%22%3A%22Qian%22%2C%22given%22%3A%22Feng%22%7D%2C%7B%22family%22%3A%22Guo%22%2C%22given%22%3A%22Yihua%22%7D%2C%7B%22family%22%3A%22Zhou%22%2C%22given%22%3A%22Yuanyuan%22%7D%2C%7B%22family%22%3A%22Xu%22%2C%22given%22%3A%22Qiang%22%7D%2C%7B%22family%22%3A%22Mao%22%2C%22given%22%3A%22Z.%20Morley%22%7D%2C%7B%22family%22%3A%22Sen%22%2C%22given%22%3A%22Subhabrata%22%7D%2C%7B%22family%22%3A%22Spatscheck%22%2C%22given%22%3A%22Oliver%22%7D%5D%2C%22accessed%22%3A%7B%22date-parts%22%3A%5B%5B%222021%22%2C6%2C7%5D%5D%7D%2C%22issued%22%3A%7B%22date-parts%22%3A%5B%5B%222013%22%2C9%2C19%5D%5D%7D%2C%22citation-key%22%3A%22huang_IndepthStudyLTE_2013%22%7D%7D%5D&quot; data-schema-version=&quot;8&quot;&gt;&lt;h1&gt;Annotations&lt;br/&gt;(5/6/2022, 2:49:44 PM)&lt;/h1&gt;<br/>&lt;p&gt;&lt;span class=&quot;highlight&quot; data-annotation=&quot;%7B%22attachmentURI%22%3A%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2F8SU8CCQA%22%2C%22annotationKey%22%3A%22EZFZEMQV%22%2C%22color%22%3A%22%23ffd400%22%2C%22pageLabel%22%3A%22363%22%2C%22position%22%3A%7B%22pageIndex%22%3A0%2C%22rects%22%3A%5B%5B122.047%2C534.989%2C292.894%2C543.005%5D%2C%5B53.798%2C524.528%2C292.894%2C532.544%5D%2C%5B53.798%2C514.067%2C78.948%2C522.083%5D%5D%7D%2C%22citationItem%22%3A%7B%22uris%22%3A%5B%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FL2KWDK96%22%5D%2C%22locator%22%3A%22363%22%7D%7D&quot;&gt;“However, the interactions among applications, network transport protocol, and the radio layer still remain unexplored.”&lt;/span&gt; &lt;span class=&quot;citation&quot; data-citation=&quot;%7B%22citationItems%22%3A%5B%7B%22uris%22%3A%5B%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FL2KWDK96%22%5D%2C%22locator%22%3A%22363%22%7D%5D%2C%22properties%22%3A%7B%7D%7D&quot;&gt;(&lt;span class=&quot;citation-item&quot;&gt;Huang et al., 2013, p. 363&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;highlight&quot; data-annotation=&quot;%7B%22attachmentURI%22%3A%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2F8SU8CCQA%22%2C%22annotationKey%22%3A%22WD3P2JKD%22%2C%22color%22%3A%22%23ffd400%22%2C%22pageLabel%22%3A%22363%22%2C%22position%22%3A%7B%22pageIndex%22%3A0%2C%22rects%22%3A%5B%5B180.362%2C493.145%2C292.894%2C501.161%5D%2C%5B53.798%2C482.685%2C292.894%2C490.701%5D%2C%5B53.798%2C472.224%2C112.05%2C480.24%5D%5D%7D%2C%22citationItem%22%3A%7B%22uris%22%3A%5B%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FL2KWDK96%22%5D%2C%22locator%22%3A%22363%22%7D%7D&quot;&gt;“We observed that LTE has significantly shorter state promotion delays and lower RTTs than those of 3G networks.”&lt;/span&gt; &lt;span class=&quot;citation&quot; data-citation=&quot;%7B%22citationItems%22%3A%5B%7B%22uris%22%3A%5B%22http%3A%2F%2Fzotero.org%2Fusers%2F4752161%2Fitems%2FL2KWDK96%22%5D%2C%22locator%22%3A%22363%22%7D%5D%2C%22properties%22%3A%7B%7D%7D&quot;&gt;(&lt;span class=&quot;citation-item&quot;&gt;Huang et al., 2013, p. 363&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;</p>

However, it seems that the two functions are the only supported functions. Because I tried several other functions in Zotero.Utilities and they all failed, e.g. randomString, rand, and etc, for the same reason as walkNoteDOM.

Could you please suggest what is the problem here? Thanks a lot.

@github-actions github-actions bot reopened this May 6, 2022
@FeralFlora
Copy link

Any update on how to solve this issue?

@dstillman
Copy link

dstillman commented May 6, 2022

@yangfurong: walkNoteDOM was added a few days ago. It's only available in the Zotero beta currently.

@yangfurong
Copy link
Author

@dstillman Ok, thanks for your comment. But other functions in Zotero.Utilities such as randomString and rand have the same issue. Do you know the possible reasons? And if I can use DOMParser or jsdom in BBT's postscript, I should be able to implement a similar walkNoteDOM function within the postscript, right?

@yangfurong
Copy link
Author

yangfurong commented May 21, 2022

Ok. I have changed the script, and now it works.

postscript
if (Translator.BetterTeX) {
    if (item.notes) {
        var my_visitor = {
            citation_uris: [],
            visitContainer: function (obj) {
                Zotero.debug("2094: visitContainer:" + obj + " " + typeof obj);
            },
            visitAnnotation: function (obj) {
                Zotero.debug("2094: visitAnnotation:" + obj + " " + typeof obj);
                json = JSON.parse(decodeURIComponent(obj.getAttribute('data-annotation')));
                Zotero.debug(JSON.stringify(json));
                const page_index = json["position"]["pageIndex"];
                const annot_key = json["annotationKey"];
                const [ , kind, lib, key ] = json["attachmentURI"].match(/^https?:\/\/zotero\.org\/(users|groups)\/((?:local\/)?[^/]+)\/items\/(.+)/);
                pdf_uri = (kind === 'users') ? `zotero://open-pdf/library/items/${key}?page=${page_index}&annotation=${annot_key}` : `zotero://open-pdf/groups/${lib}/items/${key}?page=${page_index}&annotation=${annot_key}`;

                Zotero.debug("2094: Add a PDF link:" + pdf_uri);
                obj.insertAdjacentHTML("beforeend", ` |Open PDF, <a href="${pdf_uri}">Open PDF</a>|`);
                Zotero.debug("2094: Link added:" + obj);
            },
            visitCitation: function (obj) {
                Zotero.debug("2094: visitCitation:" + obj + " " + typeof obj);
            },
            visitOtherElement: function (obj) {
                Zotero.debug("2094: visitOtherElement:" + obj + " " + typeof obj + " : " + obj.toString().charCodeAt(0) + " . " + obj.nodeType + " , " + obj.length);
                Zotero.debug("2094: " + obj.innerHTML);
                if (this.citation_uris.length != 0) {
                    Zotero.debug("2094: Add citation links:" + this.citation_uris);
                    if (obj.hasAttribute("class") && obj.getAttribute("class") === "citation-item") {
                        const uri_to_added = this.citation_uris.shift();
                        obj.insertAdjacentHTML("afterend", ` |Open item, <a href="${uri_to_added}">Open item</a>|`);
                        Zotero.debug("2094: Link added:" + obj);
                    }
                }
            },
            visitDataAttribute: function (attr, json) {
                Zotero.debug("2094: visitDataAttribute:" + attr + " " + JSON.stringify(json));
                if (attr === "data-citation") {
                    // clear the array
                    this.citation_uris.length = 0;
                    for (let temp of json["citationItems"]) {
                        const temp_uris = temp["uris"].map(val => {
                            const [ , kind, lib, key ] = val.match(/^https?:\/\/zotero\.org\/(users|groups)\/((?:local\/)?[^/]+)\/items\/(.+)/);
                            const select = (kind === 'users') ? `zotero://select/library/items/${key}` : `zotero://select/groups/${lib}/items/${key}`;
                            return select;
                        });
                        this.citation_uris.push.apply(this.citation_uris, temp_uris);
                    }
                }
            },
            visitURI: function (obj) {
                Zotero.debug("2094: visitURI:" + obj + " " + typeof obj);
                return obj;
            }
        };
        const notes = item.notes.map(note => {
            const [ , kind, lib, key ] = note.uri.match(/^https?:\/\/zotero\.org\/(users|groups)\/((?:local\/)?[^/]+)\/items\/(.+)/);
            const select = (kind === 'users') ? `zotero://select/library/items/${key}` : `zotero://select/groups/${lib}/items/${key}`;
            const modified_content = Zotero.Utilities.walkNoteDOM(note.note, my_visitor);
            Zotero.debug("2094: " + typeof modified_content + " , " + modified_content);
            return modified_content + `(Go to the note, <a href="${select}">Go to note</a>)<br/>..................................`;
        }).join('</p><p>');
        reference.add({ name: 'note', value: notes, html: true });
    }
}
@article{huang_IndepthStudyLTE_2013,
  title = {An In-Depth Study of {{LTE}}: Effect of Network Protocol and Application Behavior on Performance},
  shorttitle = {An In-Depth Study of {{LTE}}},
  author = {Huang, Junxian and Qian, Feng and Guo, Yihua and Zhou, Yuanyuan and Xu, Qiang and Mao, Z. Morley and Sen, Subhabrata and Spatscheck, Oliver},
  year = {2013},
  month = sep,
  journal = {ACM SIGCOMM Computer Communication Review},
  volume = {43},
  number = {4},
  pages = {363--374},
  note = {\section{Annotations\\
(5/10/2022, 6:59:51 PM)}

\par
``However, the interactions among applications, network transport protocol, and the radio layer still remain unexplored.'' |Open PDF, \href{zotero://open-pdf/library/items/8SU8CCQA?page=0&annotation=EZFZEMQV}{Open PDF}| (Huang et al., 2013, p. 363 |Open item, \href{zotero://select/library/items/L2KWDK96}{Open item}|)
\par
``We observed that LTE has significantly shorter state promotion delays and lower RTTs than those of 3G networks.'' |Open PDF, \href{zotero://open-pdf/library/items/8SU8CCQA?page=0&annotation=WD3P2JKD}{Open PDF}| (Huang et al., 2013, p. 363 |Open item, \href{zotero://select/library/items/L2KWDK96}{Open item}|)
\par
(Huang et al., 2013, p. 363 |Open item, \href{zotero://select/library/items/L2KWDK96}{Open item}|) test
\par
(Go to the note, \href{zotero://select/library/items/XMZP86RD}{Go to note})\\
..................................
\par
\section{Manually Generated Notes}

\par
This is a reference to (Atxutegi et al., 2018 |Open item, \href{zotero://select/library/items/8FC6JVQ6}{Open item}|)
\par
(Atxutegi et al., 2018 |Open item, \href{zotero://select/library/items/8FC6JVQ6}{Open item}|; Croitoru et al., 2015 |Open item, \href{zotero://select/library/items/IR9GYRYW}{Open item}|; Dong et al., 2018 |Open item, \href{zotero://select/library/items/BGMMKVIF}{Open item}|)
\par
\href{https://bing.com}{aaa}
\par
(Go to the note, \href{zotero://select/library/items/Y4J279RR}{Go to note})\\
..................................}
}


But, if I turn on the wokers preference, I get this error --- obj.insertAdjacentHTML is not a function.

(3)(+0000009): {better-bibtex Better BibTeX :error: (worker 1)} +null Entry.postscript failed: <Error: TypeError: obj.insertAdjacentHTML is not a function in resource://zotero-better-bibtex/Better%20BibTeX.js line 121278 > Function line undefined visitAnnotation@resource://zotero-better-bibtex/Better%20BibTeX.js line 121278 > Function:40:17 visit@chrome://zotero-better-bibtex/content/worker/zotero.js:126792:68 visit@chrome://zotero-better-bibtex/content/worker/zotero.js:126815:17 visit@chrome://zotero-better-bibtex/content/worker/zotero.js:126815:17 walkNoteDOM@chrome://zotero-better-bibtex/content/worker/zotero.js:126849:15 anonymous/result</notes<@resource://zotero-better-bibtex/Better%20BibTeX.js line 121278 > Function:81:38 anonymous/result<@resource://zotero-better-bibtex/Better%20BibTeX.js line 121278 > Function:78:23 anonymous@resource://zotero-better-bibtex/Better%20BibTeX.js line 121278 > Function:12:20 complete@resource://zotero-better-bibtex/Better%20BibTeX.js:138175:17 doExport@resource://zotero-better-bibtex/Better%20BibTeX.js:138959:7 Zotero__workerJob__environment__DOMParser</ctx.onmessage@chrome://zotero-better-bibtex/content/worker/zotero.js:169822:11 > 

@yangfurong
Copy link
Author

That will give me your postscript and a ready-to-run testcase.

Ok. I did not know this before.
I have generated a debug log. The ID is TMHU5Y7Q-refs-euc.

@retorquere
Copy link
Owner

I'm still testing, so no new log is needed yet, but could you replace your postscript with this one? It does the same, but the logging is more easy to find, and it outputs regular keys unless I'm testing. That way we can share this postscript while we're figuring this out.

postscript.txt

@github-actions
Copy link

🤖 this is your friendly neighborhood build bot announcing test build 6.7.1.2629 ("insertAdjacentHTML")

Install in Zotero by downloading test build 6.7.1.2629, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".

@yangfurong
Copy link
Author

I'm still testing, so no new log is needed yet, but could you replace your postscript with this one? It does the same, but the logging is more easy to find, and it outputs regular keys unless I'm testing. That way we can share this postscript while we're figuring this out.

postscript.txt

It seems that you are using the old script. I would like to note that it does not work as walkNoteDOM does not visit the inside text elements of <span/> elements.

I was including text nodes in children which I shouldn't have. The latest builds here fix this -- text nodes will not be visited.

Please use this latest script in which I have added your testing code.
if (Translator.BetterTeX) {
    if (item.notes) {
        var my_visitor = {
            citation_uris: [],
            visitContainer: function (obj) {
                Zotero.debug("2094: visitContainer:" + obj + " " + typeof obj);
            },
            visitAnnotation: function (obj) {
                Zotero.debug("2094: visitAnnotation:" + obj + " " + typeof obj);
                json = JSON.parse(decodeURIComponent(obj.getAttribute('data-annotation')));
                Zotero.debug("2094: " + JSON.stringify(json));
                const page_index = json["position"]["pageIndex"];
                const annot_key = Translator.preferences.testing ? 'fixed-for-test' : json.annotationKey;
                const [ , kind, lib, key ] = json["attachmentURI"].match(/^https?:\/\/zotero\.org\/(users|groups)\/((?:local\/)?[^/]+)\/items\/(.+)/);
                if (Translator.preferences.testing) key = 'fixed-for-test';
                pdf_uri = (kind === 'users') ? `zotero://open-pdf/library/items/${key}?page=${page_index}&annotation=${annot_key}` : `zotero://open-pdf/groups/${lib}/items/${key}?page=${page_index}&annotation=${annot_key}`;

                Zotero.debug("2094: Add a PDF link:" + pdf_uri);
                obj.insertAdjacentHTML("beforeend", ` |Open PDF, <a href="${pdf_uri}">Open PDF</a>|`);
                Zotero.debug("2094: Link added:" + obj);
            },
            visitCitation: function (obj) {
                Zotero.debug("2094: visitCitation:" + obj + " " + typeof obj);
            },
            visitOtherElement: function (obj) {
                Zotero.debug("2094: visitOtherElement:" + obj + " " + typeof obj + " : " + obj.toString().charCodeAt(0) + " . " + obj.nodeType + " , " + obj.length);
                Zotero.debug("2094: " + obj.innerHTML);
                if (this.citation_uris.length != 0) {
                    Zotero.debug("2094: Add citation links:" + this.citation_uris);
                    if (obj.hasAttribute("class") && obj.getAttribute("class") === "citation-item") {
                        const uri_to_added = this.citation_uris.shift();
                        obj.insertAdjacentHTML("afterend", ` |Open item, <a href="${uri_to_added}">Open item</a>|`);
                        Zotero.debug("2094: Link added:" + obj);
                    }
                }
            },
            visitDataAttribute: function (attr, json) {
                Zotero.debug("2094: visitDataAttribute:" + attr + " " + JSON.stringify(json));
                if (attr === "data-citation") {
                    // clear the array
                    this.citation_uris.length = 0;
                    for (let temp of json["citationItems"]) {
                        const temp_uris = temp["uris"].map(val => {
                            const [ , kind, lib, key ] = val.match(/^https?:\/\/zotero\.org\/(users|groups)\/((?:local\/)?[^/]+)\/items\/(.+)/);
                            if (Translator.preferences.testing) key = 'fixed-for-test';
                            const select = (kind === 'users') ? `zotero://select/library/items/${key}` : `zotero://select/groups/${lib}/items/${key}`;
                            return select;
                        });
                        this.citation_uris.push.apply(this.citation_uris, temp_uris);
                    }
                }
            },
            visitURI: function (obj) {
                Zotero.debug("2094: visitURI:" + obj + " " + typeof obj);
                return obj;
            }
        };
        const notes = item.notes.map(note => {
            const [ , kind, lib, key ] = note.uri.match(/^https?:\/\/zotero\.org\/(users|groups)\/((?:local\/)?[^/]+)\/items\/(.+)/);
            if (Translator.preferences.testing) key = 'fixed-for-test';
            const select = (kind === 'users') ? `zotero://select/library/items/${key}` : `zotero://select/groups/${lib}/items/${key}`;
            const modified_content = Zotero.Utilities.walkNoteDOM(note.note, my_visitor);
            Zotero.debug("2094: " + typeof modified_content + " , " + modified_content);
            return modified_content + `(Go to the note, <a href="${select}">Go to note</a>)<br/>..................................`;
        }).join('</p><p>');
        reference.add({ name: 'note', value: notes, html: true });
    }
}

I have tested this latest script with test build 6.7.1.2629 ("insertAdjacentHTML"). The new error is this.append is not a function in insertAdjacentHTML.

The error log.
(3)(+0000000): {better-bibtex Better BibTeX :error: (worker 4)} +null Entry.postscript failed: <Error: TypeError: this.append is not a function in chrome://zotero-better-bibtex/content/worker/zotero.js line undefined upgrade/root.insertAdjacentHTML@chrome://zotero-better-bibtex/content/worker/zotero.js:169598:13 visitAnnotation@resource://zotero-better-bibtex/Better%20BibTeX.js line 121278 > Function:41:17 visit@chrome://zotero-better-bibtex/content/worker/zotero.js:126792:68 visit@chrome://zotero-better-bibtex/content/worker/zotero.js:126815:17 visit@chrome://zotero-better-bibtex/content/worker/zotero.js:126815:17 walkNoteDOM@chrome://zotero-better-bibtex/content/worker/zotero.js:126849:15 anonymous/result</notes<@resource://zotero-better-bibtex/Better%20BibTeX.js line 121278 > Function:84:38 anonymous/result<@resource://zotero-better-bibtex/Better%20BibTeX.js line 121278 > Function:80:23 anonymous@resource://zotero-better-bibtex/Better%20BibTeX.js line 121278 > Function:12:20 complete@resource://zotero-better-bibtex/Better%20BibTeX.js:138175:17 doExport@resource://zotero-better-bibtex/Better%20BibTeX.js:138959:7 Zotero__workerJob__environment__DOMParser</ctx.onmessage@chrome://zotero-better-bibtex/content/worker/zotero.js:169872:11 >

A new support log is also reported (ID: MF977YDN-refs-euc).

@retorquere
Copy link
Owner

retorquere commented May 22, 2022

I had a bug in my tools where it wouldn't save the postscript from the log ID, sorry. I have fixed that, but the postscript in MF977YDN-refs-euc doesn't give me the append error (which was indeed an error, a new build will drop here in a few minutes that fixes that), but it errors out on the re-assignment to key, as consts can't be reassigned.

You will have to wait for the new build to drop here for further tests. I have fixed the const reassignment here, but that still gets me an error that I can't add HTML to the root.

edit: I have it reproducible now, so I should be able to fix it on my end. No further logs are needed.

@github-actions
Copy link

🤖 this is your friendly neighborhood build bot announcing test build 6.7.1.2635 ("Merge branch 'master' into gh-2094")

Install in Zotero by downloading test build 6.7.1.2635, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".

Repository owner deleted a comment from github-actions bot May 24, 2022
@retorquere
Copy link
Owner

With the testcase from MF977YDN-refs-euc I now get the same behavior with the worker as without.

@yangfurong
Copy link
Author

I got the error below with the worker enabled.

(3)(+0000178): {better-bibtex Better BibTeX :error: (worker 1)} +null Entry.postscript failed: <Error: TypeError: prop.match is not a function in chrome://zotero-better-bibtex/content/worker/zotero.js line undefined get@chrome://zotero-better-bibtex/content/worker/zotero.js:169515:11 walkNoteDOM@chrome://zotero-better-bibtex/content/worker/zotero.js:126848:1 anonymous/result</notes<@resource://zotero-better-bibtex/Better%20BibTeX.js line 121276 > Function:84:38 anonymous/result<@resource://zotero-better-bibtex/Better%20BibTeX.js line 121276 > Function:80:23 anonymous@resource://zotero-better-bibtex/Better%20BibTeX.js line 121276 > Function:12:20 complete@resource://zotero-better-bibtex/Better%20BibTeX.js:138173:17 doExport@resource://zotero-better-bibtex/Better%20BibTeX.js:138957:7 Zotero__workerJob__environment__DOMParser</ctx.onmessage@chrome://zotero-better-bibtex/content/worker/zotero.js:169842:11 >

Everything works fine with the worker disabled.

A new support log is reported (ID: KATYPEDV-refs-euc).

@retorquere
Copy link
Owner

retorquere commented May 24, 2022

reproducible. It looks like I'll need to write a significant extension to xmldom.

@github-actions
Copy link

🤖 this is your friendly neighborhood build bot announcing test build 6.7.1.2682 ("zotero-only test")

Install in Zotero by downloading test build 6.7.1.2682, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".

@yangfurong
Copy link
Author

Great! Now it works with the worker enabled! Thanks a lot.
Would it be possible to share this script on BBT's official website (scripting)? It may be useful for others who have the same use-cases.

BBT_public.txt

@retorquere
Copy link
Owner

That page has an "edit this page" at the top right, have at it 😄 . It's a hefty bit of code, so it'd require some explanation of what it does, and it's large enough that I'd stick it in a

<details><summary>....</summary>
...
</details>

block to keep the page readable.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants