Exemple #1
0
 public async Task PublishAsync(IRSession session, IApplicationShell appShell,  IFileSystem fs, string inputFilePath, string outputFilePath, PublishFormat publishFormat, Encoding encoding) {
     try {
         await RMarkdownRenderAsync(session, fs, inputFilePath, outputFilePath, GetDocumentTypeString(publishFormat), encoding.CodePage, appShell);
     } catch (IOException ex) {
         await appShell.ShowErrorMessageAsync(ex.Message);
     } catch (RException ex) {
         await appShell.ShowErrorMessageAsync(ex.Message);
     } catch (OperationCanceledException) {
     } 
 }
        private string GetDocumentTypeString(PublishFormat publishFormat) {
            switch (publishFormat) {
                case PublishFormat.Pdf:
                    return "PDF";

                case PublishFormat.Word:
                    return "WORD";
            }

            return "HTML";
        }
        private string GetDocumentTypeString(PublishFormat publishFormat) {
            switch (publishFormat) {
                case PublishFormat.Pdf:
                    return "pdf_document";

                case PublishFormat.Word:
                    return "word_document";
            }

            return "html_document";
        }
 public bool FormatSupported(PublishFormat format) {
     return format != PublishFormat.Pdf;
 }
Exemple #5
0
 public async Task PublishAsync(IRSession session, IServiceContainer services, string inputFilePath, string outputFilePath, PublishFormat publishFormat, Encoding encoding)
 {
     try {
         await RMarkdownRenderAsync(session, inputFilePath, outputFilePath, GetDocumentTypeString(publishFormat), encoding.CodePage, services);
     } catch (IOException ex) {
         await services.ShowErrorMessageAsync(ex.Message);
     } catch (RException ex) {
         await services.ShowErrorMessageAsync(ex.Message);
     } catch (OperationCanceledException) {
     }
 }
Exemple #6
0
 public bool FormatSupported(PublishFormat format) => true;
Exemple #7
0
 public bool FormatSupported(PublishFormat format)
 {
     return(format != PublishFormat.Pdf);
 }
Exemple #8
0
 public string GetCommandLine(string inputFile, string outputFile, PublishFormat publishFormat)
 {
     // Run rmarkdown::render
     return(string.Format(CultureInfo.InvariantCulture, "\"rmarkdown::render(\'{0}\', \'{1}\')\"", inputFile, GetDocumentTypeString(publishFormat)));
 }
Exemple #9
0
 public async Task PublishAsync(IRSession session, IApplicationShell appShell, IFileSystem fs, string inputFilePath, string outputFilePath, PublishFormat publishFormat, Encoding encoding)
 {
     try {
         await RMarkdownRenderAsync(session, fs, inputFilePath, outputFilePath, GetDocumentTypeString(publishFormat), encoding.CodePage, appShell);
     } catch (IOException ex) {
         await appShell.ShowErrorMessageAsync(ex.Message);
     } catch (RException ex) {
         await appShell.ShowErrorMessageAsync(ex.Message);
     } catch (OperationCanceledException) {
     }
 }
 public bool FormatSupported(PublishFormat format) {
     return format == PublishFormat.Html;
 }
Exemple #11
0
 public bool FormatSupported(PublishFormat format) {
     return true;
 }
Exemple #12
0
 public PublishOptions(IDirectoryAccessor rootDirectory, IDirectoryAccessor targetDirectory, PublishFormat format)
 {
     RootDirectory   = rootDirectory ?? throw new System.ArgumentNullException(nameof(rootDirectory));
     Format          = format;
     TargetDirectory = targetDirectory;
 }
Exemple #13
0
        protected override void ProcessRecord( )
        {
            PublishFormat pf         = PublishFormat.pfMHTML;
            bool          publishWeb = false;

            //
            //  Figure out the publish format.
            //

            List <string> candidates = new List <string>( );

            Utilities.GetCandidatesForString(OutputFormats, _outputFormat, candidates);
            if ((candidates.Count > 1) || (candidates.Count == 0))
            {
                WriteError(new ErrorRecord(new ArgumentException("Format is ambiguous"),
                                           "InvalidArgument",
                                           ErrorCategory.InvalidArgument,
                                           _outputFormat));
                return;
            }
            switch (candidates[0])
            {
            case "MHT":
                pf = PublishFormat.pfMHTML;
                break;

            case "PDF":
                pf = PublishFormat.pfPDF;
                break;

            case "DOC":
                pf = PublishFormat.pfWord;
                break;

            case "ONEPKG":
                pf = PublishFormat.pfOneNotePackage;
                break;

            case "XPS":
                pf = PublishFormat.pfXPS;
                break;

            case "WEB":
                publishWeb = true;
                break;

            default:
                throw new NotSupportedException( );
            }

            //
            //  Figure out what we're exporting.
            //

            Microsoft.Office.Interop.OneNote.ApplicationClass app = new ApplicationClass( );
            List <string> ids = new List <string>( );

            switch (ParameterSetName)
            {
            case "PSPath":
                Utilities.GetOneNoteIdsForPsPath(this, _psPath, ids);
                if ((ids.Count > 1) &&
                    !ShouldContinue("You specified multiple items to process, but only one will be converted. Continue?", "Convert"))
                {
                    return;
                }
                if (ids.Count == 0)
                {
                    Utilities.WriteInvalidPathError(this, _psPath);
                    return;
                }
                break;

            case "OneNoteId":
                ids.Add(_id);
                break;

            case "NotebookPath":
                string hierarchyId;
                app.OpenHierarchy(_notebookPath, null, out hierarchyId, CreateFileType.cftNone);
                WriteDebug("Will convert notebook: " + hierarchyId);
                ids.Add(hierarchyId);
                break;
            }

            //
            //  If we're doing change highlighting, then we need to know where the Unfiled Notes section
            //  is. We copy the page to that section, update the page XML to do the highlighting, etc.
            //

            if (_highlightChangesSince != DateTime.MaxValue)
            {
                throw new NotImplementedException( );
            }

            int progressSalt = 0;

            foreach (string id in ids)
            {
                if (!ShouldProcess(id))
                {
                    continue;
                }
                string output = _outputName;
                if (!String.IsNullOrEmpty(_pageName))
                {
                    output = System.IO.Path.Combine(output, removeInvalidFileCharacters(_pageName));
                    if (candidates[0] != "WEB")
                    {
                        output += "." + candidates[0];
                    }
                }
                WriteDebug("Exporting page " + id + " to " + output);
                if (publishWeb)
                {
                    OneNoteToRSS.OneNoteToRSS converter = new OneNoteToRSS.OneNoteToRSS( );
                    converter.OutputFolder = output;

                    if (!System.IO.Directory.Exists(output))
                    {
                        if (ShouldContinue("Directory '" + output + "' does not exist. Create it?",
                                           "Create Directory?",
                                           ref _force,
                                           ref _neverCreateDirectories))
                        {
                            System.IO.Directory.CreateDirectory(output);
                        }
                        else
                        {
                            WriteError(new ErrorRecord(new System.IO.DirectoryNotFoundException("'" + output + "' not found."),
                                                       "DirectoryNotFound",
                                                       ErrorCategory.ObjectNotFound,
                                                       output));
                            continue;
                        }
                    }

                    //
                    //  Need to get the notebook path corresponding to this ID.
                    //

                    string hierarchy;
                    app.GetHierarchy(id, HierarchyScope.hsSelf, out hierarchy);
                    XmlDocument hierarchyDoc = new XmlDocument( );
                    hierarchyDoc.LoadXml(hierarchy);
                    if (hierarchyDoc.DocumentElement.LocalName != "Notebook")
                    {
                        WriteError(new ErrorRecord(new ArgumentException("Only Notebooks may be converted to websites."),
                                                   "InvalidArgument",
                                                   ErrorCategory.InvalidArgument,
                                                   id));
                        continue;
                    }
                    string notebookPath = hierarchyDoc.DocumentElement.Attributes["path"].Value;
                    progressSalt++;
                    _progress = new ProgressRecord(_conversionActivityIdentifier + progressSalt, "Converting " + notebookPath + " To Web Notebook", "Converting");
                    WriteDebug("Outputting " + notebookPath + " to " + output);
                    converter.NotebookFolder = notebookPath;
                    if (String.IsNullOrEmpty(_customResources))
                    {
                        converter.ResourceFolder = OneNoteToRSS.OneNoteToRSS.DefaultResourceFolder;
                    }
                    else
                    {
                        converter.ResourceFolder = _customResources;
                    }
                    converter.PageConverted       += new EventHandler <OneNoteToRSS.PageConversionEventArgs>(converter_PageConverted);
                    converter.PreSectionConverted += new EventHandler <OneNoteToRSS.SectionConversionEventArgs>(converter_PreSectionConverted);
                    converter.PageSkipped         += new EventHandler <OneNoteToRSS.PageConversionEventArgs>(converter_PageSkipped);
                    converter.OpenOneNoteHierarchy( );
                    _pagesToConvert = converter.PageCount;
                    _pagesConverted = 0;
                    converter.Convert( );
                    OneNoteToRSS.FolderCopier.Copy(converter.ResourceFolder, output);
                    WriteObject(new ExportResults(id, candidates[0], output, _destinationPath));
                }
                else
                {
                    try
                    {
                        app.Publish(id, output, pf, "");
                        WriteObject(new ExportResults(id, candidates[0], output));
                    } catch (Exception e)
                    {
                        WriteError(new ErrorRecord(e, "Exception", ErrorCategory.NotSpecified, id));
                    }
                }
            }
        }
        public string GetCommandLine(string inputFile, string outputFile, PublishFormat publishFormat) {
            string arguments = string.Format(CultureInfo.InvariantCulture,
               "\"markdown::renderMarkdown(\'{0}\', \'{1}\', NULL, \'{1}\')\"", inputFile, outputFile, GetDocumentTypeString(publishFormat));

            return arguments;
        }
 public string GetCommandLine(string inputFile, string outputFile, PublishFormat publishFormat) {
     // Run rmarkdown::render
     return string.Format(CultureInfo.InvariantCulture, "\"rmarkdown::render(\'{0}\', \'{1}\')\"", inputFile, GetDocumentTypeString(publishFormat));
 }
Exemple #16
0
 public bool FormatSupported(PublishFormat format)
 {
     return(true);
 }
Exemple #17
0
            private async Task <string> GetContent(NoteEntity note, IList <DataEntity> data, PublishFormat format)
            {
                // Get content from blob
                var content = string.Empty;

                if (!string.IsNullOrEmpty(note.BlobUri))
                {
                    content = await _container.DownloadAsync(note.BlobUri);
                }

                return(format switch
                {
                    PublishFormat.FrontMatter => new StringBuilder()
                    .AppendLine("---")
                    .AppendLine($"layout: note_entry")
                    .AppendLine($"title: \"{note.Title}\"")
                    .AppendItems(data, d => $"{d.Name.Camelize()}: \"{d.Value}\"")
                    .AppendLine("---")
                    .AppendLine(content)
                    .ToString(),

                    _ => content,
                });