jupyter / nbconvert

Jupyter Notebook Conversion
https://nbconvert.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.76k stars 569 forks source link

ClearMetadataPreprocessor does not clear markdown cell tags #1715

Open antonbabkin opened 2 years ago

antonbabkin commented 2 years ago

Notebook with two cells, code and markdown, each having the same tag, gets pushed through nbconvert with --ClearMetadataPreprocessor.enabled=True. Code cell's metadata comes out empty, markdown cell metadata remains untouched.

Input notebook nb.ipynb:

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3337de7a-43db-4287-8e37-21684b2ec00c",
   "metadata": {
    "tags": [
     "u-cant-touch-this"
    ]
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "5a530402-e838-4e80-866b-fe4e3c1dfe44",
   "metadata": {
    "tags": [
     "u-cant-touch-this"
    ]
   },
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

Result after running jupyter nbconvert --ClearMetadataPreprocessor.enabled=True --to=notebook --stdout nb.ipynb

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3337de7a-43db-4287-8e37-21684b2ec00c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "5a530402-e838-4e80-866b-fe4e3c1dfe44",
   "metadata": {
    "tags": [
     "u-cant-touch-this"
    ]
   },
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

Nbconvert version: 6.4.0

rhshadrach-8451 commented 3 months ago

I would be happy to submit a PR for this, is this feature welcome? Should it be under the current flags of ClearMetadataPreprocessor.enabled and ClearMetadataPreprocessor.clear_cell_metadata?