コード例 #1
0
ファイル: test_public_api.py プロジェクト: ma-ric/pymarkups
	def test_api(self):
		all_markups = markups.get_all_markups()
		self.assertTrue(markups.MarkdownMarkup in all_markups and
		markups.ReStructuredTextMarkup in all_markups)
		markup_class = markups.find_markup_class_by_name('restructuredtext')
		self.assertEqual(markups.ReStructuredTextMarkup, markup_class)
		markup_class = markups.get_markup_for_file_name('myfile.mkd', return_class=True)
		self.assertEqual(markups.MarkdownMarkup, markup_class)
		markup = markups.get_markup_for_file_name('myfile.mkd')
		self.assertIsInstance(markup, markups.MarkdownMarkup)
コード例 #2
0
ファイル: tab.py プロジェクト: zymzs/retext
    def updateActiveMarkupClass(self):
        '''
		Update the active markup class based on the default class and
		the current filename. If the active markup class changes, the
		highlighter is rerun on the input text, the markup object of
		this tab is replaced with one of the new class and the
		activeMarkupChanged signal is emitted.
		'''
        previousMarkupClass = self.activeMarkupClass

        self.activeMarkupClass = find_markup_class_by_name(
            globalSettings.defaultMarkup)

        if self._fileName:
            markupClass = get_markup_for_file_name(self._fileName,
                                                   return_class=True)
            if markupClass:
                self.activeMarkupClass = markupClass

        if self.activeMarkupClass != previousMarkupClass:
            self.highlighter.docType = self.activeMarkupClass.name if self.activeMarkupClass else None
            self.highlighter.rehighlight()

            self.activeMarkupChanged.emit()
            self.triggerPreviewUpdate()
コード例 #3
0
ファイル: tab.py プロジェクト: daffodil/retext
 def getMarkupClass(self):
     if self.fileName:
         markupClass = get_markup_for_file_name(self.fileName,
                                                return_class=True)
         if markupClass:
             return markupClass
     return self.p.defaultMarkup
コード例 #4
0
ファイル: tab.py プロジェクト: Tamriel/retext
	def getMarkupClass(self):
		if self.fileName:
			markupClass = get_markup_for_file_name(
				self.fileName, return_class=True)
			if markupClass:
				return markupClass
		return self.p.defaultMarkup
コード例 #5
0
	def openSourceFile(self, linkPath):
		"""Finds and opens the source file for link target fileToOpen.

		When links like [test](test) are clicked, the file test.md is opened.
		It has to be located next to the current opened file.
		Relative paths like [test](../test) or [test](folder/test) are also possible.
		"""

		fileToOpen = self.resolveSourceFile(linkPath)
		if exists(fileToOpen) and get_markup_for_file_name(fileToOpen, return_class=True):
			self.p.openFileWrapper(fileToOpen)
			return fileToOpen
		if get_markup_for_file_name(fileToOpen, return_class=True):
			if not QFile.exists(fileToOpen) and QFileInfo(fileToOpen).dir().exists():
				if self.promptFileCreation(fileToOpen):
					self.p.openFileWrapper(fileToOpen)
					return fileToOpen
コード例 #6
0
	def getMarkupClass(self, fileName=None):
		if fileName is None:
			fileName = self.fileNames[self.ind]
		if fileName:
			markupClass = markups.get_markup_for_file_name(
				fileName, return_class=True)
			if markupClass:
				return markupClass
		return self.defaultMarkup
コード例 #7
0
ファイル: window.py プロジェクト: dreamrom/retext
	def getMarkupClass(self, fileName=None):
		if fileName is None:
			fileName = self.currentTab.fileName
		if fileName:
			markupClass = markups.get_markup_for_file_name(
				fileName, return_class=True)
			if markupClass:
				return markupClass
		return self.defaultMarkup
コード例 #8
0
	def openInternal(self, link):
		url = link.url()
		isLocalHtml = (link.scheme() in ('file', '') and url.endswith('.html'))
		if url.startswith('#'):
			self.scrollToAnchor(url[1:])
		elif link.isRelative() and get_markup_for_file_name(url, return_class=True):
			fileToOpen = QDir.current().filePath(url)
			if not QFileInfo(fileToOpen).completeSuffix() and self._fileName:
				fileToOpen += '.' + QFileInfo(self.tab.fileName).completeSuffix()
			self.tab.p.openFileWrapper(fileToOpen)
		elif globalSettings.handleWebLinks and isLocalHtml:
			self.setSource(link)
		else:
			QDesktopServices.openUrl(link)
コード例 #9
0
ファイル: tab.py プロジェクト: Tamriel/retext
	def readTextFromFile(self, encoding=None):
		openfile = QFile(self.fileName)
		openfile.open(QFile.ReadOnly)
		stream = QTextStream(openfile)
		encoding = encoding or globalSettings.defaultCodec
		if encoding:
			stream.setCodec(encoding)
		text = stream.readAll()
		openfile.close()
		markupClass = get_markup_for_file_name(self.fileName, return_class=True)
		self.setMarkupClass(markupClass)
		modified = bool(encoding) and (self.editBox.toPlainText() != text)
		self.editBox.setPlainText(text)
		self.editBox.document().setModified(modified)
コード例 #10
0
def export_file(args):
    markup = markups.get_markup_for_file_name(args.input_file)
    with open(args.input_file) as input:
        text = input.read()
    if not markup:
        sys.exit('Markup not available.')
    converted = markup.convert(text)

    html = converted.get_whole_html(include_stylesheet=args.include_stylesheet,
                                    fallback_title=args.fallback_title,
                                    webenv=args.web_environment)

    with open(args.output_file, 'w') as output:
        output.write(html)
コード例 #11
0
def export_file(args):
    markup = markups.get_markup_for_file_name(args.input_file)
    with open(args.input_file) as input:
        text = input.read()
    if not markup:
        sys.exit('Markup not available.')
    converted = markup.convert(text)

    html = converted.get_whole_html(include_stylesheet=args.include_stylesheet,
                                    fallback_title=args.fallback_title,
                                    webenv=args.web_environment)

    with open(args.output_file, 'w') as output:
        output.write(html)
コード例 #12
0
ファイル: tab.py プロジェクト: retext-project/retext
 def openInternal(self, link):
     url = link.url()
     isLocalHtml = link.scheme() in ("file", "") and url.endswith(".html")
     if url.startswith("#"):
         self.scrollToAnchor(url[1:])
     elif link.isRelative() and get_markup_for_file_name(url, return_class=True):
         fileToOpen = QDir.current().filePath(url)
         if not QFileInfo(fileToOpen).completeSuffix() and self._fileName:
             fileToOpen += "." + QFileInfo(self.tab.fileName).completeSuffix()
         self.tab.p.openFileWrapper(fileToOpen)
     elif globalSettings.handleWebLinks and isLocalHtml:
         self.setSource(link)
     else:
         QDesktopServices.openUrl(link)
コード例 #13
0
ファイル: tab.py プロジェクト: daffodil/retext
 def readTextFromFile(self, encoding=None):
     openfile = QFile(self.fileName)
     openfile.open(QFile.ReadOnly)
     stream = QTextStream(openfile)
     encoding = encoding or globalSettings.defaultCodec
     if encoding:
         stream.setCodec(encoding)
     text = stream.readAll()
     openfile.close()
     markupClass = get_markup_for_file_name(self.fileName,
                                            return_class=True)
     self.setMarkupClass(markupClass)
     modified = bool(encoding) and (self.editBox.toPlainText() != text)
     self.editBox.setPlainText(text)
     self.editBox.document().setModified(modified)
コード例 #14
0
ファイル: tab.py プロジェクト: starofrainnight/retext
	def openSourceFile(self, fileToOpen):
		"""Finds and opens the source file for link target fileToOpen.

		When links like [test](test) are clicked, the file test.md is opened.
		It has to be located next to the current opened file.
		Relative paths like [test](../test) or [test](folder/test) are also possible.
		"""
		if self.fileName:
			currentExt = splitext(self.fileName)[1]
			basename, ext = splitext(fileToOpen)
			if ext in ('.html', '') and exists(basename + currentExt):
				self.p.openFileWrapper(basename + currentExt)
				return basename + currentExt
		if exists(fileToOpen) and get_markup_for_file_name(fileToOpen, return_class=True):
			self.p.openFileWrapper(fileToOpen)
			return fileToOpen
コード例 #15
0
ファイル: tab.py プロジェクト: zymzs/retext
    def openSourceFile(self, fileToOpen):
        """Finds and opens the source file for link target fileToOpen.

		When links like [test](test) are clicked, the file test.md is opened.
		It has to be located next to the current opened file.
		Relative paths like [test](../test) or [test](folder/test) are also possible.
		"""
        if self.fileName:
            currentExt = splitext(self.fileName)[1]
            basename, ext = splitext(fileToOpen)
            if ext in ('.html', '') and exists(basename + currentExt):
                self.p.openFileWrapper(basename + currentExt)
                return basename + currentExt
        if exists(fileToOpen) and get_markup_for_file_name(fileToOpen,
                                                           return_class=True):
            self.p.openFileWrapper(fileToOpen)
            return fileToOpen
コード例 #16
0
ファイル: window.py プロジェクト: dreamrom/retext
	def openFileMain(self, encoding=None):
		openfile = QFile(self.currentTab.fileName)
		openfile.open(QIODevice.ReadOnly)
		stream = QTextStream(openfile)
		if encoding:
			stream.setCodec(encoding)
		elif globalSettings.defaultCodec:
			stream.setCodec(globalSettings.defaultCodec)
		text = stream.readAll()
		openfile.close()
		markupClass = markups.get_markup_for_file_name(
			self.currentTab.fileName, return_class=True)
		self.currentTab.highlighter.docType = (markupClass.name if markupClass else '')
		self.currentTab.markup = self.getMarkup()
		if self.defaultMarkup:
			self.currentTab.highlighter.docType = self.defaultMarkup.name
		editBox = self.currentTab.editBox
		modified = bool(encoding) and (editBox.toPlainText() != text)
		editBox.setPlainText(text)
		self.setCurrentFile()
		editBox.document().setModified(modified)
		self.setWindowModified(modified)
コード例 #17
0
	def openFileMain(self, encoding=None):
		openfile = QFile(self.fileNames[self.ind])
		openfile.open(QIODevice.ReadOnly)
		stream = QTextStream(openfile)
		if encoding:
			stream.setCodec(encoding)
		elif globalSettings.defaultCodec:
			stream.setCodec(globalSettings.defaultCodec)
		text = stream.readAll()
		openfile.close()
		markupClass = markups.get_markup_for_file_name(
			self.fileNames[self.ind], return_class=True)
		self.highlighters[self.ind].docType = (markupClass.name if markupClass else '')
		self.markups[self.ind] = self.getMarkup()
		if self.defaultMarkup:
			self.highlighters[self.ind].docType = self.defaultMarkup.name
		editBox = self.editBoxes[self.ind]
		modified = bool(encoding) and (editBox.toPlainText() != text)
		editBox.setPlainText(text)
		self.setCurrentFile()
		editBox.document().setModified(modified)
		self.setWindowModified(modified)
コード例 #18
0
ファイル: tab.py プロジェクト: retext-project/retext
    def updateActiveMarkupClass(self):
        """
		Update the active markup class based on the default class and
		the current filename. If the active markup class changes, the
		highlighter is rerun on the input text, the markup object of
		this tab is replaced with one of the new class and the
		activeMarkupChanged signal is emitted.
		"""
        previousMarkupClass = self.activeMarkupClass

        self.activeMarkupClass = find_markup_class_by_name(globalSettings.defaultMarkup)

        if self._fileName:
            markupClass = get_markup_for_file_name(self._fileName, return_class=True)
            if markupClass:
                self.activeMarkupClass = markupClass

        if self.activeMarkupClass != previousMarkupClass:
            self.highlighter.docType = self.activeMarkupClass.name if self.activeMarkupClass else None
            self.highlighter.rehighlight()

            self.activeMarkupChanged.emit()
            self.triggerPreviewUpdate()
コード例 #19
0
	def test_api_instance(self):
		markup = markups.get_markup_for_file_name('myfile.mkd')
		self.assertIsInstance(markup, markups.MarkdownMarkup)