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

Markdown.lua - Steam version update #901

Merged
merged 18 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 82 additions & 40 deletions docs/markdown.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,98 @@ markdown
========
myk002 marked this conversation as resolved.
Show resolved Hide resolved

.. dfhack-tool::
:summary: Exports the text you see on the screen for posting online.
:tags: unavailable

This tool saves a copy of a text screen, formatted in markdown, for posting to
Reddit (among other places). See `forum-dwarves` if you want to export BBCode
for posting to the Bay 12 forums.

This script will attempt to read the current screen, and if it is a text
viewscreen (such as the dwarf 'thoughts' screen or an item 'description') then
append a marked-down version of this text to the output file. Previous entries
in the file are not overwritten, so you may use the ``markdown`` command
multiple times to create a single document containing the text from multiple
screens, like thoughts from several dwarves or descriptions from multiple
artifacts.

The screens which have been tested and known to function properly with this
script are:

#. dwarf/unit 'thoughts' screen
#. item/art 'description' screen
#. individual 'historical item/figure' screens
#. manual pages
#. announcements screen
#. combat reports screen
#. latest news (when meeting with liaison)

There may be other screens to which the script applies. It should be safe to
attempt running the script with any screen active. An error message will inform
you when the selected screen is not appropriate for this script.
:summary: Save description of selected unit/item in Markdown file
glotov4 marked this conversation as resolved.
Show resolved Hide resolved
:tags: dfhack | items | units
glotov4 marked this conversation as resolved.
Show resolved Hide resolved

Saves the description of a selected unit or item to a Markdown file encoded in UTF-8.

By default, data is stored in the `Dwarf Fortress/markdown_{YourWorldName}.md`
glotov4 marked this conversation as resolved.
Show resolved Hide resolved
file in the root game directory.

For units, the script retrieves:
#. Name, race, age, profession
#. Description from the Unit/Health/Description screen
#. Traits from the Unit/Personality/Traits screen
The script tested on dwarves, dogs, elves, goblins, beasts,
and is expected to work with all units
glotov4 marked this conversation as resolved.
Show resolved Hide resolved

For items, it retrieves:
#. Decorated name (e.g., "☼«☼Chalk Statue of Dakas☼»☼")
glotov4 marked this conversation as resolved.
Show resolved Hide resolved
#. Full description from the item's view sheet
The script works for most items with in-game descriptions and names, including those in storage,
glotov4 marked this conversation as resolved.
Show resolved Hide resolved
on the ground, installed as a building, or worn/carried by units.

By default, entries are appended, not overwritten, allowing the ``markdown`` command
to compile descriptions of multiple items & units in a single document.
glotov4 marked this conversation as resolved.
Show resolved Hide resolved

Usage
-----

::

markdown [-n] [<name>]
markdown [-o | --overwrite] [<filename>]

Appends the description of the selected unit/item
to ``markdown_{world_name}.md`` file by default.
Specifying a filename will append to ``markdown_{filename}.md`` instead,
which is useful for organizing data by category or topic.
The [-o] argument tells the script to overwrite the output file.

Options
-------

The output is appended to the ``md_export.md`` file by default. If an alternate
name is specified, then a file named like ``md_{name}.md`` is used instead.
``-o``, ``--overwrite``
Overwrite the output file, deleting previous entries.

Examples
--------

``markdown``
Appends the contents of the current screen to the ``md_export.md`` file.
``markdown artifacts``
Appends the contents of the current screen to the ``md_artifacts.md`` file.
::

Options
-------
markdown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is a tool that could benefit from a global hotkey - (Ctrl-Shift-s?) so people can click on things with the mouse and export them quickly with their left hand. This would be added to the keybindings file in the other repo: https://github.com/DFHack/dfhack/blob/develop/data/init/dfhack.keybindings.init

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it later, thank you

Copy link
Contributor Author

@glotov4 glotov4 Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct way to add keybinding? I'm not sure what @dawrfmode means, and maybe I should be using @textviewer instead

save description of selected unit or item in markdown format
keybinding add Ctrl-Shift-S@dwarfmode markdown

Copy link
Member

@myk002 myk002 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that refers to the "context" where the hotkey should be considered active. dwarfmode is fort mode, but you can make the hotkey local to more specific contexts (the strings returned from dfhack.gui.getCurFocus(true)). that way, the hotkey will only show up in the DFHack context menu where it is applicable.

e.g.

keybinding add Ctrl-Shift-S@dwarfmode/ViewSheets/UNIT|dwarfmode/ViewSheets/ITEM|...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, let's add it later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I call the command with the hotkey, it doesn't show success message (or any message). Is it expected behavior?

Copy link
Contributor Author

@glotov4 glotov4 Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using Shift+R.

keybinding list Shift-R gives an empty list.

The potential conflicts I see are:
Ctrl+R - recording
(easy to misclick)

and

materials: q->workshop; b->select items:
#keybinding add Shift-R "job-material RHYOLITE"
Which is fine, because we will only use the command in our context window

Pull request to add the hotkey:
DFHack/dfhack#4470


Example output for a selected chalk statue in the world "Orid Tamun", appended to the default ``markdown_Orid_Tamun.md`` file:

[...previous entries...]

### ☼Chalk Statue of Bìlalo Bandbeach☼

#### Description:
This is a well-crafted chalk statue of Bìlalo Bandbeach. The item is an image of
Bìlalo Bandbeach the elf and Lani Lyricmonks the Learned the ettin in chalk by
Domas Uthmiklikot. Lani Lyricmonks the Learned is striking down Bìlalo Bandbeach.
The artwork relates to the killing of the elf Bìlalo Bandbeach by the
ettin Lani Lyricmonks the Learned with Hailbite in The Forest of Indignation in 147.

---
::

``markdown -o descriptions``

Example output for a selected unit Lokum Alnisendok, written to the newly overwritten ``markdown_descriptions.md`` file:
::

### Lokum Alnisendok, dwarf, 27 years old Presser.

#### Description:
A short, sturdy creature fond of drink and industry.

He is very quick to tire.

His very long beard is neatly combed. His very long sideburns are braided.
His very long moustache is neatly combed. His hair is clean-shaven. He is average in size.
His nose is sharply hooked. His nose bridge is convex. His gold eyes are slightly wide-set.
His somewhat tall ears are somewhat narrow. His hair is copper. His skin is copper.

#### Personality:
He has an amazing memory, but he has a questionable spatial sense and poor focus.

He doesn't generally think before acting. He feels a strong need to reciprocate any favor done for him.
He enjoys the company of others. He does not easily hate or develop negative feelings. He generally
finds himself quite hopeful about the future. He tends to be swayed by the emotions of others.
He finds obligations confining, though he is conflicted by this for more than one reason. He doesn't
tend to hold on to grievances. He has an active imagination.

He needs alcohol to get through the working day.

``-n``
Overwrite the contents of output file instead of appending.
---
Loading
Loading