I would like to add some additional information to the Darios answer.
Only one configuration file can be used by tex4ht, but its content
can be included by the \input command, so it is possible to reuse
parts of the configuration between different projects. It is possible to save the particular files in the local TEXMF directory, so they are accessible from any location on a computer.
In your case, as you created a custom package, you need to create a configuration file for that package, called packagename.4ht. You provided configuration file for your package myMedia.4ht in your answer. I would change it a bit:
\NewConfigure{myMedia}{2}%
\renewcommand\myMedia[1]{\a:myMedia#1\b:myMedia}
%\Configure{myMedia}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="}\NoFonts}{\HCode{" type="video/mp4"></video></div>}\EndNoFonts}
\Hinput{myMedia}
The \NewConfigure{myMedia}{2} command creates so called hooks which can be inserted into the redefined commands and configured using the \Configure command. It does exactly the same thing as the \NewConfigure from your answer, but it is a bit simpler.
It is better to keep the \Configure commands out of the package configuration files. Why? When tex4ht process the document preamble, it loads configuration files for all used packages, in order to redefine commands and insert the hooks. After that, configuration files for the current output format are executed. tex4ht can thus support HTML, ODT and some more output formats. So configurations for HTML are provided in html4.4ht or html5.4ht files, for ODT format in ooffice.4ht etc. It is of course not possible for you to insert your custom configurations to these files, as your edits would be removed in the next tex4ht update.
If you are sure to support only HTML, you can keep the \Configure command in myMedia.4ht, even if it is not the optimal solution. Another possibility is to put it in the .cfg file and last one is to create a custom output format. I will show this possibility just for the educational purposes:
Output formats are defined in the tex4ht.4ht file. This is the definition for html5 format, for example:
\Configure{html5}{%
\:CheckOption{info}\if:Option
\Hinclude[*]{infoht4.4ht}\fi
\:CheckOption{info}\if:Option
\Hinclude[*]{infomml.4ht}\fi
\Hinclude[*]{html4.4ht}%
\Hinclude[*]{unicode.4ht}%
\:CheckOption{mathml}\if:Option%
\else\:CheckOption{mathml-}\fi%
\if:Option%
\Hinclude[*]{mathml.4ht}%
\Hinclude[*]{html-mml.4ht}%
\else
\Hinclude[*]{html4-math.4ht}%
\fi
\:CheckOption{svg}%
\if:Option \else\:CheckOption{svg-}\fi
\if:Option \else\:CheckOption{svg-obj}\fi
\if:Option \else\:CheckOption{svg-inline}\fi
\if:Option \Hinclude[*]{svg-option.4ht}%
\:CheckOption{info}\if:Option \Hinclude[*]{infosvg.4ht}\fi
\fi
\Hinclude[*]{html5.4ht}%
}
The \Configure command here declares a code that is executed when the mark used as it's argument is used as an option for tex4ht. html5 is added automatically by make4ht so this code is executed by default.
The custom output format can be defined in the tex4ht.usr file. It is possible to place it in the local TEXMF tree, for example ~/texmf/tex/latex/tex4ht/tex4ht.usr seems to work. It's contents may look like this:
\Configure{myhtml5}{%
\:CheckOption{info}\if:Option
\Hinclude[*]{infoht4.4ht}\fi
\:CheckOption{info}\if:Option
\Hinclude[*]{infomml.4ht}\fi
\Hinclude[*]{html4.4ht}%
\Hinclude[*]{unicode.4ht}%
\:CheckOption{mathml}\if:Option%
\else\:CheckOption{mathml-}\fi%
\if:Option%
\Hinclude[*]{mathml.4ht}%
\Hinclude[*]{html-mml.4ht}%
\else
\Hinclude[*]{html4-math.4ht}%
\fi
\:CheckOption{svg}%
\if:Option \else\:CheckOption{svg-}\fi
\if:Option \else\:CheckOption{svg-obj}\fi
\if:Option \else\:CheckOption{svg-inline}\fi
\if:Option \Hinclude[*]{svg-option.4ht}%
\:CheckOption{info}\if:Option \Hinclude[*]{infosvg.4ht}\fi
\fi
\Hinclude[*]{html5.4ht}%
\Hinclude[*]{myconfig.4ht}
}
The difference to the previous listing is that the mark is named myhtml5 and a new file is requested, myconfig.4ht. To request this output format, run
make4ht filename.tex "myhtml5"
The custom configurations can be then added to the myconfig.4ht file, which can be saved in the same location as tex4ht.usr:
\exit:ifnot{myMedia}
\ConfigureHinput{myMedia}
\Configure{myMedia}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="}\NoFonts}
{\HCode{" type="video/mp4"></video></div>}\EndNoFonts}
\endinput\empty\empty\empty\empty\empty\empty
\endinput
I've used the template for a package from the tex4ht documentation. In general, the code for a package needs to be enclosed in \ConfigureHinput{packagename} ... \endinput. This ensures that it is executed only when the package had been used in the document. You would get warnings about missing configurations and probably unwanted HTML code in your document otherwise. The used packages are registered for the processing using the \Hinput command in the package .4ht file.
The configuration for myMedia has been modified a bit, in order to handle correctly the paragraphs. The original configuration produced invalid HTML code due to this issue. You can copy the \Configure command to the .cfg file or to the myMedia.4ht if you decide to use a simpler solutions. This is the only really necessary fix from my answer.
The last bit of information I want to provide in my answer is that it is possible to use a simpler command for inclusion of an external CSS file:
\Preamble{xhtml}
\begin{document}
\Configure{AddCss}{samplestyle.css}
\EndPreamble
It will not include the code from samplestyle.css to the main CSS file, it will just include a link to the HTML header. I think it is a preferable way in most cases.
This is the result of command
make4ht -um draft -c sample.cfg sample.tex "myhtml5"
<hr class="figure" /><div class="figure"
>
<a id="x1-21"></a>
<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="test.mp4" type="video/mp4"></video></div>
<br /> <div class="caption"
><span class="id">Figure 1: </span><span
class="content">test</span></div><!--tex4ht:label?: x1-21 -->
</div><hr class="endfigure" />
tex4htconfig file, such as\Preamble{...},\begin{document}, and\EndPreamble, it will probably be difficult to have two of them (how would things be stacked/ordered then?). I haven't tested, but you might be able to use\input{myMedia}insidesample.cfgfor a duly preparedmyMedia.tex. – gusbrs Feb 26 '19 at 09:53