public void ConvertDocument(string sourceMarkdownFilePath, string outputDocxFilePath)
        {
            // Check the style existence within the docx document.
            var lackedStyleIds = GetLackedStyleIdsWithinBaseFile(BaseFilePath, UserSettingStyleMap);

            if (lackedStyleIds.Length != 0)
            {
                var ex = new LackOfStyleWithinBaseFileException(string.Format("The base file does not contain some style IDs: {0}", string.Join(", ", lackedStyleIds)));
                ex.Data.Add("LackedStyleIds", lackedStyleIds);
                throw ex;
            }

            var mdDoc = ParseMarkdownDocument(sourceMarkdownFilePath);

            // Build the Word document based-on the base docx file.
            using (var manipulator = new WordDocumentManipulator(BaseFilePath, outputDocxFilePath, true))
            {
                var baseFolderPathForRelativePath = Path.GetDirectoryName(sourceMarkdownFilePath);
                var blockConverter = new BlockConverter(manipulator, UserSettingStyleMap, baseFolderPathForRelativePath);

                foreach (var block in mdDoc)
                {
                    var elements = blockConverter.Convert(block);
                    manipulator.AppendElementsToDocumentBody(elements);
                }

                // Save the Word document.
                manipulator.Save();
            }
        }
Ejemplo n.º 2
0
        private string GetFencedCodeBlockStyleId(string adhocStyleId)
        {
            if (string.IsNullOrWhiteSpace(adhocStyleId))
            {
                return(UserSettingStyleMap.GetStyleId(UserSettingStyleMap.StyleMapKeyType.Code, null));
            }

            if (Manipulator.StyleManager.ContainsStyleId(adhocStyleId))
            {
                return(adhocStyleId);
            }
            else
            {
                var ex = new LackOfStyleWithinBaseFileException(string.Format("The base file does not contain the style ID: {0}", adhocStyleId));
                ex.Data.Add("LackedStyleIds", new string[] { adhocStyleId });
                throw ex;
            }
        }