Skip to content

Cleaning: Regexes for figure and table sections WP #215

Description

@oldenbourglaura

WordPress Chapters

  • Copy chapter wikitext from MediaWiki to VS Code

Images

A) Count the figures in the chapter

  • Count and write down the number of images in the chapter for reference

FIND

[[File:

B) Find all h6 with the word "Figure" in it, add a comment above and replace the header with bolds

  • We want to get rid of h6 values. We want to have the image titles as simple bolds, with a comment

FIND regex*

={6}\s*(.*[Ff]igure.*?)\s*={6}

REPLACE

<!-- START IMG -->
<!-- IMG TITLE -->
'''$1'''

C) Find the h4 that comes right before a file

  • We want to get rid of h4 values around images. We want to have the image captions as simple bolds, with a comment

C1) EMPTY h4

  • Some of the h4 are empty, we want to delete them

FIND regex*

={4}\s*={4}\n\n\[\[File:

REPLACE

<!-- IMG FILE -->
[[File:

C2) NOT EMPTY h4:

  • After that, convert the remains h4 with actual content into bolds

FIND regex*

(={4})\s*(.+?)\s*(={4})\n\n\[\[File:

REPLACE

<!-- IMG CAPTION -->
'''$2'''
<!-- IMG FILE -->
[[File:

D) Find the end of an image section and add a comment

  • Add an end comment after image section (for future use)

FIND regex*

(\[\[File:[^\]]+\]\][\s\S]*?)\n(<(div|span)[^>]*>)

REPLACE

$1
<!-- END IMG -->
$2

Tables

A) Count the tables in the chapter

FIND

{| class="wikitable"

B) Find all h6 with the word "Table" in it, add a comment above and replace the header with bolds

FIND regex*

={6}\s*(.*[Tt]able.*?)\s*={6}

REPLACE

<!-- START TABLE -->
'''$1'''

C) Find the h4 that comes right before a file

  • We want to get rid of h4 values around tables. We want to have the table captions as simple bolds, with a comment

C1) EMPTY h4

  • Some of the h4 are empty, we want to delete them
  • Manually

FIND regex*


REPLACE


C2) NOT EMPTY h4:

  • After that, convert the remains h4 with actual content into bolds
  • Manually

FIND regex*


REPLACE


FIND

{| class="wikitable"

REPLACE

<!-- TABLE -->
{| class="wikitable"

D) Add an end comment

FIND

|}

REPLACE

|}
<!-- END TABLE -->
  • Check for image for Supplementary Material
  • Paste chapter back into wiki and save
  • Use a special comment for this revision

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions