diff --git a/MANUAL.txt b/MANUAL.txt
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -1,7 +1,7 @@
 ---
 title: Pandoc User's Guide
 author: John MacFarlane
-date: January 12, 2022
+date: January 14, 2022
 ---
 
 # Synopsis
@@ -5727,13 +5727,16 @@
        before lower (default is lower before upper).
 
 `notes-after-punctuation`
-:    If true (the default), pandoc will put footnote citations
+:    If true (the default for note styles), pandoc will put
+     footnote references or superscripted numerical citations
      after following punctuation.  For example, if the source
      contains `blah blah [@jones99].`, the result will look like
      `blah blah.[^1]`, with the note moved after the period and
      the space collapsed.  If false, the space will still be
      collapsed, but the footnote will not be moved after the
-     punctuation.
+     punctuation.  The option may also be used in numerical styles
+     that use superscripts for citation numbers (but for these
+     styles the default is not to move the citation).
 
 
 # Slide shows
diff --git a/changelog.md b/changelog.md
--- a/changelog.md
+++ b/changelog.md
@@ -1,8 +1,36 @@
 # Revision history for pandoc
 
+## pandoc 2.17.0.1 (2022-01-14)
+
+  * Require pandoc-lua-marshal 0.1.3.1 (#7831, Albert Krewinkel).
+    Fixes a problem with `List.includes` and `List.find` that caused a
+    Lua stackoverflow and subsequent program crash.
+
+  * HTML template: load header-includes before math (#7833, Kolen Cheung).
+    MathJax expect the config comes before loading the MathJax script.
+    This change of order allows one to config MathJax via
+    header-includes, which loads before the MathJax script. Cf. #2750.
+
+  * When reading defaults file, stop at a line `...`.  This line signals
+    the end of a YAML document.  This restores the behavior we got with
+    HsYaml.  yaml complains about content past this line.  See
+    https://github.com/jgm/pandoc/issues/4627#issuecomment-1012438765
+
+  * Text.Pandoc.Citeproc: allow `notes-after-punctuation` to work with
+    numerical styles that use superscripts (e.g.
+    american-medical-association.csl), as well as with note styles. The
+    default setting of `notes-after-punctuation` is true for note styles
+    and false otherwise.  This restores a behavior of pandoc-citeproc
+    that wasn't properly carried over to Citeproc (#7826, cf.
+    jgm/pandoc-citeproc#384).
+
+  * Use commonmark-pandoc 0.2.1.2 (#7769).
+
+  * Add FAQ on images in ipynb containers (#7749, Kolen Cheung).
+
 ## pandoc 2.17 (2022-01-12)
 
-  * Support `markua` as an output format Add (#1871, Tim Wisotzki and
+  * Support `markua` as an output format (#1871, Tim Wisotzki and
     Saumel Lemmenmeier). Markua is a markdown variant used by Leanpub.
 
   * Add text wrapping for HTML output (#7764). Previously the HTML writer
@@ -42,7 +70,7 @@
       Previously `@item [p. 12; @item2]` was incorrectly parsed as
       three citations rather than two.  This is now fixed by ensuring
       that `prefix` doesn't gobble any semicolons.
-    + Revert changes to `inlinesInBlanacedBrackets` (commit fa83246),
+    + Revert changes to `inlinesInBalancedBrackets` (commit fa83246),
       which caused regressions.
     + Improve detection of pipe table line widths (#7713).  Fixed
       calculation of maximum column widths in pipe tables.  It is
@@ -120,7 +148,7 @@
 
   * Markdown writer:
 
-    + Add new exported function `writeMarkua` from T.P.Writers.Markdown
+    + Add new exported function `writeMarkua` from Text.Pandoc.Writers.Markdown
       [API change] (#1871, Tim Wisotzki and Saumel Lemmenmeier).
     + Fix indentation issue in footnotes (#7801).
     + Avoid extra space before citation suffix if it already starts
@@ -269,11 +297,9 @@
       `document-css`.  Setting the `document-css` variable will cause it
       not to be ignored.
 
-  * HTML template:
-
-    + Add abstract (#7588, Jannik Buhr, John MacFarlane).  By default,
-      a localized title (the word "Abstract") will be used, unless the
-      variable `abstract-title` is set.
+  * HTML template:  Add abstract (#7588, Jannik Buhr, John MacFarlane).
+    By default, a localized title (the word "Abstract") will be
+    used, unless the variable `abstract-title` is set.
 
   * ConTeXt template:  Make title appear in PDF title bar.  This is
     recommended for accessibility reasons.  Note: doesn't work with macOS
@@ -385,7 +411,7 @@
       attributes are accessible through the `.attr` field. Rows in `TableHead`
       and `TableFoot` are available via the `.rows` field. Row objects have a
       `.cells` field, containing the list of table cells.
-    + Simplify code of `pandoc.utils.stringify`. Minor behavior change:
+    + [Simplify](Simplify) code of `pandoc.utils.stringify`. Minor behavior change:
       plain strings nested in tables are now included in the result string.
     + Simplify and deprecate function `pandoc.utils.equals`. The function
       is no longer required for element comparisons; it is now an alias
diff --git a/data/templates/default.html4 b/data/templates/default.html4
--- a/data/templates/default.html4
+++ b/data/templates/default.html4
@@ -23,12 +23,12 @@
 $for(css)$
   <link rel="stylesheet" href="$css$" type="text/css" />
 $endfor$
-$if(math)$
-  $math$
-$endif$
 $for(header-includes)$
   $header-includes$
 $endfor$
+$if(math)$
+  $math$
+$endif$
 </head>
 <body>
 $for(include-before)$
diff --git a/data/templates/default.html5 b/data/templates/default.html5
--- a/data/templates/default.html5
+++ b/data/templates/default.html5
@@ -23,15 +23,15 @@
 $for(css)$
   <link rel="stylesheet" href="$css$" />
 $endfor$
+$for(header-includes)$
+  $header-includes$
+$endfor$
 $if(math)$
   $math$
 $endif$
   <!--[if lt IE 9]>
     <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
   <![endif]-->
-$for(header-includes)$
-  $header-includes$
-$endfor$
 </head>
 <body>
 $for(include-before)$
diff --git a/man/pandoc.1 b/man/pandoc.1
--- a/man/pandoc.1
+++ b/man/pandoc.1
@@ -1,7 +1,7 @@
 '\" t
-.\" Automatically generated by Pandoc 2.16.2
+.\" Automatically generated by Pandoc 2.17
 .\"
-.TH "Pandoc User\[cq]s Guide" "" "January 12, 2022" "pandoc 2.17" ""
+.TH "Pandoc User\[cq]s Guide" "" "January 14, 2022" "pandoc 2.17.0.1" ""
 .hy
 .SH NAME
 pandoc - general markup converter
@@ -6745,13 +6745,17 @@
 .RE
 .TP
 \f[B]\f[CB]notes-after-punctuation\f[B]\f[R]
-If true (the default), pandoc will put footnote citations after
-following punctuation.
+If true (the default for note styles), pandoc will put footnote
+references or superscripted numerical citations after following
+punctuation.
 For example, if the source contains \f[C]blah blah [\[at]jones99].\f[R],
 the result will look like \f[C]blah blah.[\[ha]1]\f[R], with the note
 moved after the period and the space collapsed.
 If false, the space will still be collapsed, but the footnote will not
 be moved after the punctuation.
+The option may also be used in numerical styles that use superscripts
+for citation numbers (but for these styles the default is not to move
+the citation).
 .SH SLIDE SHOWS
 .PP
 You can use pandoc to produce an HTML + JavaScript slide presentation
diff --git a/pandoc.cabal b/pandoc.cabal
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -1,6 +1,6 @@
 cabal-version:   2.4
 name:            pandoc
-version:         2.17
+version:         2.17.0.1
 build-type:      Simple
 license:         GPL-2.0-or-later
 license-file:    COPYING.md
@@ -462,7 +462,7 @@
                  citeproc              >= 0.6.0.1  && < 0.7,
                  commonmark            >= 0.2.1.1  && < 0.3,
                  commonmark-extensions >= 0.2.3    && < 0.3,
-                 commonmark-pandoc     >= 0.2.1.1  && < 0.3,
+                 commonmark-pandoc     >= 0.2.1.2  && < 0.3,
                  connection            >= 0.3.1,
                  containers            >= 0.4.2.1  && < 0.7,
                  data-default          >= 0.4      && < 0.8,
@@ -491,7 +491,7 @@
                  mtl                   >= 2.2      && < 2.3,
                  network               >= 2.6,
                  network-uri           >= 2.6      && < 2.8,
-                 pandoc-lua-marshal    >= 0.1.3    && < 0.2,
+                 pandoc-lua-marshal    >= 0.1.3.1  && < 0.2,
                  pandoc-types          >= 1.22.1   && < 1.23,
                  parsec                >= 3.1      && < 3.2,
                  pretty                >= 1.1      && < 1.2,
diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs
--- a/src/Text/Pandoc/App/Opt.hs
+++ b/src/Text/Pandoc/App/Opt.hs
@@ -52,6 +52,7 @@
 import Data.Default (def)
 import qualified Data.Text as T
 import qualified Data.Map as M
+import qualified Data.ByteString.Char8 as B8
 import Text.Pandoc.Definition (Meta(..), MetaValue(..))
 import Data.Aeson (defaultOptions, Options(..), Result(..), fromJSON, camelTo2)
 import Data.Aeson.TH (deriveJSON)
@@ -692,7 +693,7 @@
   setVerbosity $ optVerbosity opt
   modify $ \defsState -> defsState{ curDefaults = Just file }
   inp <- readFileStrict file
-  case decodeEither' inp of
+  case decodeEither' (B8.unlines . takeWhile (/= "...") . B8.lines $ inp) of
       Right f -> f opt
       Left err'  -> throwError $
          PandocParseError
diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs
--- a/src/Text/Pandoc/Citeproc.hs
+++ b/src/Text/Pandoc/Citeproc.hs
@@ -93,8 +93,8 @@
                      B.divWith ("ref-" <> ident,["csl-entry"],[]) . B.para .
                          insertSpace $ out)
                       (resultBibliography result)
-  let moveNotes = styleIsNoteStyle sopts &&
-           maybe True truish (lookupMeta "notes-after-punctuation" meta)
+  let moveNotes = maybe (styleIsNoteStyle sopts) truish
+                   (lookupMeta "notes-after-punctuation" meta)
   let cits = resultCitations result
 
   let metanocites = lookupMeta "nocite" meta
diff --git a/stack.yaml b/stack.yaml
--- a/stack.yaml
+++ b/stack.yaml
@@ -27,7 +27,7 @@
 - lua-2.0.2
 - tasty-hslua-1.0.0
 - tasty-lua-1.0.0
-- pandoc-lua-marshal-0.1.3
+- pandoc-lua-marshal-0.1.3.1
 - pandoc-types-1.22.1
 - aeson-pretty-0.8.9
 - unicode-transforms-0.4.0
@@ -35,7 +35,7 @@
 - texmath-0.12.4
 - commonmark-0.2.1.1
 - commonmark-extensions-0.2.3
-- commonmark-pandoc-0.2.1.1
+- commonmark-pandoc-0.2.1.2
 - citeproc-0.6.0.1
 - ipynb-0.2
 ghc-options:
diff --git a/test/command/7826.md b/test/command/7826.md
new file mode 100644
--- /dev/null
+++ b/test/command/7826.md
@@ -0,0 +1,78 @@
+```
+% pandoc -t plain --citeproc
+---
+bibliography: command/biblio.bib
+suppress-bibliography: true
+csl: command/american-medical-association.csl
+notes-after-punctuation: true
+---
+
+In numerous recent works [@item1; @item2], statistician
+Foo and Bar have criticized XXX.
+^D
+In numerous recent works,^(1,2) statistician Foo and Bar have criticized
+XXX.
+```
+```
+% pandoc -t plain --citeproc
+---
+bibliography: command/biblio.bib
+suppress-bibliography: true
+csl: command/american-medical-association.csl
+---
+
+In numerous recent works [@item1; @item2], statistician
+Foo and Bar have criticized XXX.
+^D
+In numerous recent works^(1,2), statistician Foo and Bar have criticized
+XXX.
+```
+```
+% pandoc -t plain --citeproc
+---
+bibliography: command/biblio.bib
+suppress-bibliography: true
+csl: command/chicago-fullnote-bibliography.csl
+notes-after-punctuation: false
+---
+
+In numerous recent works [@item1; @item2], statistician
+Foo and Bar have criticized XXX.
+^D
+In numerous recent works[1], statistician Foo and Bar have criticized
+XXX.
+
+[1] John Doe, First Book (Cambridge: Cambridge University Press, 2005);
+John Doe, “Article,” Journal of Generic Studies 6 (2006): 33–34.
+```
+```
+% pandoc -t plain --citeproc
+---
+bibliography: command/biblio.bib
+suppress-bibliography: true
+csl: command/chicago-fullnote-bibliography.csl
+---
+
+In numerous recent works [@item1; @item2], statistician
+Foo and Bar have criticized XXX.
+^D
+In numerous recent works,[1] statistician Foo and Bar have criticized
+XXX.
+
+[1] John Doe, First Book (Cambridge: Cambridge University Press, 2005);
+John Doe, “Article,” Journal of Generic Studies 6 (2006): 33–34.
+```
+```
+% pandoc -t plain --citeproc
+---
+bibliography: command/biblio.bib
+suppress-bibliography: true
+notes-after-punctuation: true
+---
+
+In numerous recent works [@item1; @item2], statistician
+Foo and Bar have criticized XXX.
+^D
+In numerous recent works (Doe 2005, 2006), statistician Foo and Bar have
+criticized XXX.
+```
diff --git a/test/command/american-medical-association.csl b/test/command/american-medical-association.csl
new file mode 100644
--- /dev/null
+++ b/test/command/american-medical-association.csl
@@ -0,0 +1,279 @@
+<?xml version="1.0" encoding="utf-8"?>
+<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only" page-range-format="expanded" default-locale="en-US">
+  <info>
+    <title>American Medical Association 11th edition</title>
+    <title-short>AMA (11th ed.)</title-short>
+    <id>http://www.zotero.org/styles/american-medical-association</id>
+    <link href="http://www.zotero.org/styles/american-medical-association" rel="self"/>
+    <link href="http://www.zotero.org/styles/american-medical-association-10th-edition" rel="template"/>
+    <link href="https://westlibrary.txwes.edu/sites/default/files/pdf/AMACitationStyle.pdf" rel="documentation"/>
+    <link href="https://www.amamanualofstyle.com/fileasset/AMAMOS/aaaAMWA%20presentation%20Nov%202019%20FULL.pdf" rel="documentation"/>
+    <author>
+      <name>Julian Onions</name>
+      <email>julian.onions@gmail.com</email>
+    </author>
+    <contributor>
+      <name>Christian Pietsch</name>
+      <uri>http://purl.org/net/pietsch</uri>
+    </contributor>
+    <contributor>
+      <name>Daniel W Chan</name>
+      <email>danwchan@protonmail.com</email>
+    </contributor>
+    <contributor>
+      <name>Patrick O'Brien</name>
+      <email>obrienpat86@gmail.com</email>
+    </contributor>
+    <category citation-format="numeric"/>
+    <category field="medicine"/>
+    <summary>The American Medical Association style as used in JAMA. Version 11 as per November-2019.</summary>
+    <updated>2020-04-23T13:38:04+00:00</updated>
+    <rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
+  </info>
+  <locale xml:lang="en">
+    <terms>
+      <term name="page-range-delimiter">-</term>
+    </terms>
+  </locale>
+  <macro name="editor">
+    <names variable="editor">
+      <name name-as-sort-order="all" sort-separator=" " initialize-with="" delimiter=", " delimiter-precedes-last="always"/>
+      <label form="short" prefix=", "/>
+    </names>
+  </macro>
+  <macro name="author">
+    <group suffix=".">
+      <names variable="author">
+        <name name-as-sort-order="all" sort-separator=" " initialize-with="" delimiter=", " delimiter-precedes-last="always"/>
+        <label form="short" prefix=", "/>
+        <substitute>
+          <names variable="editor"/>
+          <text macro="title"/>
+        </substitute>
+      </names>
+    </group>
+  </macro>
+  <macro name="access">
+    <choose>
+      <if type="article-newspaper" match="none">
+        <choose>
+          <if variable="DOI">
+            <text value="doi:"/>
+            <text variable="DOI"/>
+          </if>
+          <else-if variable="URL">
+            <group delimiter=". ">
+              <choose>
+                <if type="webpage post post-weblog" match="any">
+                  <date variable="issued" prefix="Published " form="text"/>
+                </if>
+              </choose>
+              <group>
+                <text term="accessed" text-case="capitalize-first" suffix=" "/>
+                <date variable="accessed">
+                  <date-part name="month" suffix=" "/>
+                  <date-part name="day" suffix=", "/>
+                  <date-part name="year"/>
+                </date>
+              </group>
+              <text variable="URL"/>
+            </group>
+          </else-if>
+        </choose>
+      </if>
+    </choose>
+  </macro>
+  <macro name="title">
+    <choose>
+      <if type="bill book graphic legal_case legislation motion_picture report song" match="any">
+        <text variable="title" font-style="italic" text-case="title"/>
+      </if>
+      <else>
+        <text variable="title"/>
+      </else>
+    </choose>
+  </macro>
+  <macro name="publisher">
+    <text variable="publisher"/>
+  </macro>
+  <macro name="edition">
+    <choose>
+      <if is-numeric="edition">
+        <group delimiter=" ">
+          <number variable="edition" form="ordinal"/>
+          <text term="edition" form="short"/>
+        </group>
+      </if>
+      <else>
+        <text variable="edition" suffix="."/>
+      </else>
+    </choose>
+  </macro>
+  <citation collapse="citation-number">
+    <sort>
+      <key variable="citation-number"/>
+    </sort>
+    <layout delimiter="," vertical-align="sup">
+      <text variable="citation-number"/>
+      <group prefix="(" suffix=")">
+        <label variable="locator" form="short" strip-periods="true"/>
+        <text variable="locator"/>
+      </group>
+    </layout>
+  </citation>
+  <bibliography hanging-indent="false" et-al-min="7" et-al-use-first="3" second-field-align="flush">
+    <layout>
+      <text variable="citation-number" suffix=". "/>
+      <text macro="author"/>
+      <text macro="title" prefix=" " suffix="."/>
+      <choose>
+        <if type="bill book graphic legislation motion_picture report song" match="any">
+          <group suffix="." prefix=" " delimiter=" ">
+            <group delimiter=" ">
+              <text term="volume" form="short" text-case="capitalize-first" strip-periods="true"/>
+              <text variable="volume" suffix="."/>
+            </group>
+            <text macro="edition"/>
+            <text macro="editor" prefix="(" suffix=")"/>
+          </group>
+          <text macro="publisher" prefix=" "/>
+          <group suffix="." prefix="; ">
+            <date variable="issued">
+              <date-part name="year"/>
+            </date>
+            <text variable="page" prefix=":"/>
+          </group>
+        </if>
+        <else-if type="chapter paper-conference entry-dictionary entry-encyclopedia" match="any">
+          <group prefix=" " delimiter=" ">
+            <text term="in" text-case="capitalize-first" suffix=":"/>
+            <text macro="editor"/>
+            <text variable="container-title" font-style="italic" suffix="." text-case="title"/>
+            <group delimiter=" ">
+              <text term="volume" form="short" text-case="capitalize-first" strip-periods="true"/>
+              <text variable="volume" suffix="."/>
+            </group>
+            <text macro="edition"/>
+            <text variable="collection-title" suffix="."/>
+            <group suffix=".">
+              <text macro="publisher"/>
+              <group suffix="." prefix="; ">
+                <date variable="issued">
+                  <date-part name="year"/>
+                </date>
+                <text variable="page" prefix=":"/>
+              </group>
+            </group>
+          </group>
+        </else-if>
+        <else-if type="article-newspaper">
+          <text variable="container-title" font-style="italic" prefix=" " suffix=". "/>
+          <choose>
+            <if variable="URL">
+              <group delimiter=". " suffix=".">
+                <text variable="URL"/>
+                <group prefix="Published ">
+                  <date variable="issued">
+                    <date-part name="month" suffix=" "/>
+                    <date-part name="day" suffix=", "/>
+                    <date-part name="year"/>
+                  </date>
+                </group>
+                <group>
+                  <text term="accessed" text-case="capitalize-first" suffix=" "/>
+                  <date variable="accessed">
+                    <date-part name="month" suffix=" "/>
+                    <date-part name="day" suffix=", "/>
+                    <date-part name="year"/>
+                  </date>
+                </group>
+              </group>
+            </if>
+            <else>
+              <group delimiter=":" suffix=".">
+                <group>
+                  <date variable="issued">
+                    <date-part name="month" suffix=" "/>
+                    <date-part name="day" suffix=", "/>
+                    <date-part name="year"/>
+                  </date>
+                </group>
+                <text variable="page"/>
+              </group>
+            </else>
+          </choose>
+        </else-if>
+        <else-if type="legal_case">
+          <group suffix="," prefix=" " delimiter=" ">
+            <text macro="editor" prefix="(" suffix=")"/>
+          </group>
+          <group prefix=" " delimiter=" ">
+            <text variable="container-title"/>
+            <text variable="volume"/>
+          </group>
+          <text variable="page" prefix=", " suffix=" "/>
+          <group prefix="(" suffix=")." delimiter=" ">
+            <text variable="authority"/>
+            <date variable="issued">
+              <date-part name="year"/>
+            </date>
+          </group>
+        </else-if>
+        <else-if type="webpage post post-weblog" match="any">
+          <text variable="container-title" prefix=" " suffix="."/>
+        </else-if>
+        <else-if type="speech">
+          <group prefix=" " suffix=":">
+            <choose>
+              <if variable="genre">
+                <text variable="genre" suffix=" "/>
+                <text term="presented at"/>
+              </if>
+              <else>
+                <text term="presented at" text-case="capitalize-first"/>
+              </else>
+            </choose>
+          </group>
+          <group delimiter="; " prefix=" " suffix=".">
+            <text variable="event"/>
+            <group>
+              <date delimiter=" " variable="issued">
+                <date-part name="month"/>
+                <date-part name="day" suffix=","/>
+                <date-part name="year"/>
+              </date>
+            </group>
+            <text variable="event-place"/>
+          </group>
+        </else-if>
+        <else>
+          <text macro="editor" prefix=" " suffix="."/>
+          <group prefix=" " suffix=".">
+            <text variable="container-title" font-style="italic" form="short" strip-periods="true" suffix="."/>
+            <group delimiter=";" prefix=" ">
+              <choose>
+                <if variable="issue volume" match="any">
+                  <date variable="issued">
+                    <date-part name="year"/>
+                  </date>
+                </if>
+                <else>
+                  <group delimiter=" ">
+                    <text value="Published online"/>
+                    <date form="text" date-parts="year-month-day" variable="issued"/>
+                  </group>
+                </else>
+              </choose>
+              <group>
+                <text variable="volume"/>
+                <text variable="issue" prefix="(" suffix=")"/>
+              </group>
+            </group>
+            <text variable="page" prefix=":"/>
+          </group>
+        </else>
+      </choose>
+      <text prefix=" " macro="access"/>
+    </layout>
+  </bibliography>
+</style>
diff --git a/trypandoc/Makefile b/trypandoc/Makefile
--- a/trypandoc/Makefile
+++ b/trypandoc/Makefile
@@ -1,7 +1,7 @@
 CGIBIN=/home/website/cgi-bin
 TRYPANDOC=/home/website/pandoc.org/try/
 CGI=${CGIBIN}/trypandoc
-BIN=/home/jgm/.local/bin/trypandoc
+BIN=/home/jgm/.cabal/bin/trypandoc
 
 install: ${CGI} ${TRYPANDOC}/index.html
 
