Problem/Motivation

This suggestion is inspired by this issue
https://www.drupal.org/project/markdownify/issues/3512571

In the current version, this module uses the 'full' view mode to create the HTML for conversion.

Suppose the view mode is configurable, so a site owner could create a 'markdown' view mode that would only include the fields desirable for the markdown version.

Attached is a Claude-assisted (& tested) patch to accomplish this goal.

Proposed resolution

If the maintainers want to pursue, I or others can turn it into a merge request

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mindbet created an issue. See original summary.

jiisuominen’s picture

StatusFileSize
new5.39 KB

Hey!

I liked this idea, but the patch didn't apply properly. So I rerolled this and made some minor improvements. Namely to add dropdown list for selecting view mode.

slattery’s picture

I made a sub module that uses the hook_markdownify_entity_build_alter hook exposed by the markdownify api, with form alter functions that manage third party settings for view mode overrides globally per entity type, then down per bundle type if wanted.

I will work more on this, including on getting into the normal gitlab/drupal cycle, either as a standalone, or if desirable, this could be a submodule next to file_attachment to be distributed with markdownify.

https://github.com/slattery/markdownify_viewmodes

medha kumari made their first commit to this issue’s fork.

medha kumari’s picture

Status: Active » Needs review

Hi, I create MR for this. Please check and review. Thanks!

christophweber made their first commit to this issue’s fork.

christophweber’s picture

Status: Needs review » Fixed

Merged, thank you!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

mxr576’s picture

Status: Fixed » Needs work

The new view_mode property could have been required at the config schema level, since it is required at the form level.

An update hook should have been also added to initialize this new property on existing sites.

These two together could eliminate this unnecessary nullability check in the code.

    // Use configured view mode if not explicitly provided.
    if ($view_mode === 'full') {
      $view_mode = $this->config('markdownify.settings')->get('view_mode') ?: 'full';
    }

Btw, this could be only me, but the // Use configured view mode if not explicitly provided. does not seems to be aligned with the surrounding code logic.

christophweber’s picture

Status: Needs work » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

christophweber’s picture

Status: Fixed » Closed (won't fix)

I reverted the commit and am closing this issue, because Drupal view modes as of today do not include page titles.
The original issue https://www.drupal.org/project/markdownify/issues/3512571 can remain as a roadmap item.

Page titles are important in 99% of all use cases for MarkDown output (or any Drupal output).
People wishing to have view mode support can still use the code from the MR fork https://git.drupalcode.org/issue/markdownify-3543406/-/tree/view_mode in conjunction with a contrib module such as Manage Display or Show Title.

Supporting view modes in Markdownify without additional dependencies will require deeper work in the original issue, or perhaps a change in Drupal Core.